/*
 CC0-1.0
*/
(function(t,Z){"object"===typeof exports&&"undefined"!==typeof module?Z(exports):"function"===typeof define&&define.amd?define(["exports"],Z):Z(t.H3DU=t.H3DU||{})})(this,function(t){function Z(a,b,c){this._init(a,b,c)}function va(a,b){this.context=b=b&&b.getContext?b.getContext():b;this.loadedTexture=b.createTexture();b.activeTexture(b.TEXTURE0);b.pixelStorei(b.UNPACK_FLIP_Y_WEBGL,0);var c=b.TEXTURE_CUBE_MAP;b.bindTexture(c,this.loadedTexture);for(var d=0;6>d;d++)"src"in a.textures[d].image?b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+
d,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,a.textures[d].image):b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+d,0,b.RGBA,a.getWidth(),a.getHeight(),0,b.RGBA,b.UNSIGNED_BYTE,a.image);Z.textureFilters(b,a,new H3DU.TextureInfo,c)}function aa(a){this.lights=a}function y(){this._projectionMatrix=H3DU.Math.mat4identity();this._viewMatrix=H3DU.Math.mat4identity();this.lights=new H3DU.Lights;this._frustum=this._globalShader=this._projectionUpdater=null;this.shapes=[]}function w(a,b){this.curve=a;this.curveParam=b}function ta(a,
b,c,d,e){for(var f=.5*(c-b),g=b+f,h=0,m=0,n=0;n<ma.length;n+=3){var k=ma[n+2],l=ma[n+1],q=ma[n],v=a(f*q+g),h=h+k*v,m=m+l*v;0<q&&(v=a(-f*q+g),h+=k*v,m+=l*v)}h=h*f*d;m=m*f*d;return 1E-6>Math.abs(h-m)?m+(m-h)/8191:10<=e?m+(m-h)/8191:ta(a,b,g,d,e+1)+ta(a,g,c,d,e+1)}function r(a,b,c){if(0>=a.length)throw Error();if(!b)throw Error();this.bits=c||0;this.controlPoints=a;0!==(this.bits&r.WEIGHTED_BIT)&&0===(this.bits&r.HOMOGENEOUS_BIT)&&(this.controlPoints=r._convertToHomogen(this.controlPoints));a=b.length-
this.controlPoints.length;if(1>a||a>this.controlPoints.length)throw Error();r._checkKnots(b,a-1);c=this.controlPoints[0].length;var d=1;0!==(this.bits&r.DIVIDE_BIT)&&(d=2);if(c<d)throw Error();this.fastBezier=!1;if(a===this.controlPoints.length&&4>=a){this.fastBezier=!0;for(c=0;c<a;c++)if(0!==b[c]){this.fastBezier=!1;break}for(c=a;this.fastBezier&&c<b.length;c++)if(1!==b[c]){this.fastBezier=!1;break}}this.knots=b;this.buffer=[]}function J(a,b,c,d){this.bits=d||0;0!==(this.bits&r.WEIGHTED_BIT)&&0===
(this.bits&r.HOMOGENEOUS_BIT)&&(a=J._convertToHomogen(a));d=a.length;if(0>=d)throw Error();var e=a[0].length;if(0>=e)throw Error();var f=a[0][0].length,g=1;0!==(this.bits&r.DIVIDE_BIT)&&(g=2);if(f<g)throw Error();if(!b||!c)throw Error();this.degreeU=b.length-e-1;this.degreeV=c.length-d-1;this.vcplen=d;this.ucplen=e;if(1>this.degreeU||this.degreeU+1>e)throw Error();if(1>this.degreeV||this.degreeV+1>d)throw Error();r._checkKnots(b,this.degreeU);r._checkKnots(c,this.degreeV);this.knotsU=b;this.knotsV=
c;this.bufferU=[];this.bufferV=[];this.controlPoints=a}function ja(a,b,c){("undefined"!==typeof b&&null!==b||"undefined"!==typeof c&&null!==c)&&console.warn("Unused parameters u1 and/or u2 given");this.curve=r.clamped(a,a.length-1,0)}function ka(a,b,c,d,e){"undefined"!==typeof b&&null!==b&&console.warn("Unused parameter u1 is defined");"undefined"!==typeof c&&null!==c&&console.warn("Unused parameter u2 is defined");"undefined"!==typeof d&&null!==d&&console.warn("Unused parameter v1 is defined");"undefined"!==
typeof e&&null!==e&&console.warn("Unused parameter v2 is defined");this.surface=J.clamped(a,a[0].length-1,a.length-1,0)}function na(){this._frameBuffers=[]}function pa(a,b){if(0>a||0>b)throw Error("width or height negative");this.width=Math.ceil(a);this.height=Math.ceil(b)}function ga(a,b,c,d,e){this.shininess=32;this.ambient=[.2,.2,.2];this.diffuse=[1,1,1,1];this.specular=[.2,.2,.2];this.emission=[0,0,0];this.shader=this.occlusionMap=this.emissionMap=this.normalMap=this.specularMap=this.texture=
null;!a||a.constructor!==Array&&"string"!==typeof a?"undefined"!==typeof a&&null!==a&&this.setParams(a):this.setParams({ambient:a,diffuse:b,specular:c,shininess:d,emission:e})}function oa(a){this.albedo=[1,1,1,1];this.albedoMap=null;this.metalness=0;this.metalnessMap=null;this.roughness=.35;this.roughnessMap=null;this.specular=[.2,.2,.2];this.specularMap=null;this.workflow=H3DU.PbrMaterial.Metallic;this.normalMap=null;this.emission=[0,0,0];this.shader=this.occlusionMap=this.emissionMap=null;this.invertRoughness=
!1;"undefined"!==typeof a&&null!==a&&this.setParams(a)}function wa(a,b){this.batch=a;this.clearStencil=this.clearDepth=this.clearColor=!0;this.shader=this.frameBuffer=null;this.useFrameBufferSize=!1;this.setParams("undefined"===typeof b?null:b)}function fa(){this.builder=new N;this.norm=this.pos=null;this.autoNormal=!1}if("undefined"!==typeof window&&null!==window&&("undefined"===typeof window.Promise||null===window.Promise)){var R=function(a){this._state=0;this._timeout=this._value=null;this._cb=
{fulfilled:[],rejected:[]};this._thenPromises=[];a&&this._invokeResolver(a)};R.resolve=function(a){return new this(function(b){b(a)})};R.reject=function(a){return new this(function(b,c){c(a)})};R.all=R.when=function(a){return new this(function(b,c){var d=0,e=[];a.forEach(function(a,g){d++;a.then(function(a){e[g]=a;d--;d||b(e)},function(a){d=1/0;c(a)})})})};R.race=function(a){return new this(function(b,c){a.forEach(function(a){a.then(b,c)})})};R.prototype.then=function(a,b){this._cb.fulfilled.push(a);
this._cb.rejected.push(b);var c=new R(null);this._thenPromises.push(c);0<this._state&&this._schedule();return c};R.prototype.fulfill=function(a){if(0!==this._state)return this;this._state=1;this._value=a;this._thenPromises.length&&this._schedule();return this};R.prototype.reject=function(a){if(0!==this._state)return this;this._state=2;this._value=a;this._thenPromises.length&&this._schedule();return this};R.prototype.resolve=function(a){if(a===this)this.reject(new TypeError("Promise resolved by its own instance"));
else if(a instanceof this.constructor)a.chain(this);else{var b;if("undefined"===typeof a||null===a||"object"!==typeof a&&"function"!==typeof a)this.fulfill(a);else{try{b=a.then}catch(f){this.reject(f);return}if("function"===typeof b){var c=!1,d=function(a){c||(c=!0,this.resolve(a))},e=function(a){c||(c=!0,this.reject(a))};try{b.call(a,d.bind(this),e.bind(this))}catch(f){c||this.reject(f)}}else this.fulfill(a)}}};R.prototype.chain=function(a){return this.then(function(b){a.resolve(b)},function(b){a.reject(b)})};
R.prototype["catch"]=function(a){return this.then(null,a)};R.prototype._schedule=function(){this._timeout||(this._timeout=setTimeout(this._processQueue.bind(this),0))};R.prototype._processQueue=function(){for(this._timeout=null;this._thenPromises.length;){var a=this._cb.fulfilled.shift(),b=this._cb.rejected.shift();this._executeCallback(1===this._state?a:b)}};R.prototype._executeCallback=function(a){var b=this._thenPromises.shift();if("function"!==typeof a)1===this._state?b.fulfill(this._value):b.reject(this._value);
else try{var c=a(this._value);b.resolve(c);return c}catch(d){b.reject(d)}};R.prototype._invokeResolver=function(a){try{a(this.resolve.bind(this),this.reject.bind(this))}catch(b){this.reject(b)}};"undefined"!==typeof window&&null!==window&&(window.Promise=R)}if("undefined"===typeof window.requestAnimationFrame||null===window.requestAnimationFrame){var p=("undefined"===typeof window.mozRequestAnimationFrame?null:window.mozRequestAnimationFrame)||("undefined"===typeof window.webkitRequestAnimationFrame?
null:window.webkitRequestAnimationFrame)||("undefined"===typeof window.msRequestAnimationFrame?null:window.msRequestAnimationFrame);"undefined"!==typeof p&&null!==p&&(window.requestAnimationFrame=p);if("undefined"===typeof window.requestAnimationFrame||null===window.requestAnimationFrame)window.requestAnimationFrame=function(a){window.setTimeout(function(){a(window.performance.now())},17);return 0}}if("undefined"===typeof window.performance||null===window.performance)window.performance={};if("undefined"===
typeof window.performance.now||null===window.performance.now)window.performance.now=function(){return 1E3*(new Date).getTime()-window.performance._startTime},window.performance._startTime=1E3*(new Date).getTime();if("undefined"===typeof Object.keys||null===Object.keys)Object.keys=function(a){var b=[],c;for(c in a)Object.prototype.hasOwnProperty.call(a,c)&&(b[b.length]=c);return b};var qa=function(a){return a&&"undefined"!==typeof WebGLRenderingContext&&null!==WebGLRenderingContext&&a instanceof WebGLRenderingContext||
a&&"undefined"!==typeof WebGL2RenderingContext&&null!==WebGL2RenderingContext&&a instanceof WebGL2RenderingContext?!0:!!(a&&"compileShader"in a)},xa=function(a){if(!a||!a.getContext)return null;var b=null,c={preserveDrawingBuffer:!0,alpha:!1};c.antialias=window.devicePixelRatio&&1<window.devicePixelRatio?!1:!0;try{b=a.getContext("webgl2",c)}catch(d){b=null}if(!b)try{b=a.getContext("webgl",c)}catch(d){b=null}if(!b)try{b=a.getContext("experimental-webgl",c)}catch(d){b=null}if(!b)try{b=a.getContext("moz-webgl",
c)}catch(d){b=null}if(!b)try{b=a.getContext("webkit-3d",c)}catch(d){b=null}if(!b)try{b=a.getContext("2d",c)}catch(d){b=null}qa(b)&&(b.getExtension("OES_element_index_uint"),b.getExtension("OES_standard_derivatives"));return b},ya=function(a,b,c){function d(a,b,c){return function(d){a&&a(d);b.successes[c]=d;return!0}}function e(a,b,c){return function(d){a&&a(d);b.failures[c]=d;return!0}}if(!a||0===a.length)return Promise.resolve({successes:[],failures:[],results:[]});for(var f={successes:[],failures:[],
results:[]},g=[],h=0;h<a.length;h++){var m=h;g.push(a[h].then(d(b,f,m),e(c,f,m)))}return Promise.all(g).then(function(a){for(var b=0;b<f.successes.length;b++)"undefined"===typeof f.successes[b]&&(f.successes.splice(b,1),--b);for(b=0;b<f.failures.length;b++)"undefined"===typeof f.failures[b]&&(f.failures.splice(b,1),--b);f.results=a;return Promise.resolve(f)})},za=function(){throw Error();};(function(a){a.skipWhite=function(a,c,d){for(;c<d;){var b=a.charCodeAt(c);if(32===b||13===b||12===b||9===b||
10===b)++c;else break}return c};a.parseComma=function(b,c,d){var e=c;c=a.skipWhite(b,c,d);return c<d&&44===b.charCodeAt(c)?a.skipWhite(b,c+1,d):e};a.parseEndparen=function(b,c,d){var e=c;c=a.skipWhite(b,c,d);return c<d&&41===b.charCodeAt(c)?c+1:e};a.hsl=function(b,c,d,e){var f,g;f=c;if((g=a.parseHue(b,c,d,e,0))===c)return f;c=g;if((g=a.sepPct(b,c,d,e,1))===c)return f;c=g;if((g=a.sepPct(b,c,d,e,2))===c)return f;c=g;g=a.parseEndparen(b,c,d);if(g===c)return f;c=g;b=a.hlsToRgb(e[0],e[2],e[1]);e[0]=b[0];
e[1]=b[1];e[2]=b[2];e[3]=255;return c};a.pct=function(b,c,d,e,f){var g=a.parseNumber(b,c,d);if(g!==c){if(g>=d||37!==b.charAt(g))return c;e[f]=255*a.stringToPercent(b,c,g)/100;return g+1}return g};a.parseByte=function(b,c,d,e,f){d=a.parseInteger(b,c,d,!0);d!==c&&(e[f]=a.stringToByte(b,c,d));return d};a.parseHue=function(b,c,d,e,f){var g=c;c=a.skipWhite(b,c,d);d=a.parseNumber(b,c,d);return d!==c?(e[f]=a.stringToHue(b,c,d),d):g};a.sepByte=function(b,c,d,e,f){var g=a.parseComma(b,c,d);return g!==c?a.parseByte(b,
g,d,e,f):g};a.sepPct=function(b,c,d,e,f){var g=a.parseComma(b,c,d);return g!==c?a.pct(b,g,d,e,f):g};a.sepAlpha=function(b,c,d,e,f){var g=a.parseComma(b,c,d);g!==c&&(c=g,g=a.parseNumber(b,c,d),g!==c&&(e[f]=a.stringToAlpha(b,c,g)));return g};a.hsla=function(b,c,d,e){var f,g;f=c;if((g=a.parseHue(b,c,d,e,0))===c)return f;c=g;if((g=a.sepPct(b,c,d,e,1))===c)return f;c=g;if((g=a.sepPct(b,c,d,e,2))===c)return f;c=g;if((g=a.sepAlpha(b,c,d,e,3))===c)return f;c=g;g=a.hlsToRgb(e[0],e[2],e[1]);e[0]=g[0];e[1]=
g[1];e[2]=g[2];g=a.parseEndparen(b,c,d);return g===c?f:g};a.rgba=function(b,c,d,e){var f,g;f=c;var h=c=a.skipWhite(b,c,d),m=!0;(g=a.pct(b,c,d,e,0))===c?m=!1:c=g;m&&(g=a.sepPct(b,c,d,e,1))===c?m=!1:c=g;m&&(g=a.sepPct(b,c,d,e,2))===c?m=!1:c=g;m&&(g=a.sepAlpha(b,c,d,e,3))===c?m=!1:c=g;m||(c=h,m=!0,(g=a.parseByte(b,c,d,e,0))===c?m=!1:c=g,m&&(g=a.sepByte(b,c,d,e,1))===c?m=!1:c=g,m&&(g=a.sepByte(b,c,d,e,2))===c?m=!1:c=g,m&&(g=a.sepAlpha(b,c,d,e,3))===c?m=!1:c=g);if(!m)return f;g=a.parseEndparen(b,c,d);
return g===c?f:g};a.rgb=function(b,c,d,e){var f,g;f=c;var h=c=a.skipWhite(b,c,d),m=!0;(g=a.pct(b,c,d,e,0))===c?m=!1:c=g;m&&(g=a.sepPct(b,c,d,e,1))===c?m=!1:c=g;m&&(g=a.sepPct(b,c,d,e,2))===c?m=!1:c=g;m||(c=h,m=!0,(g=a.parseByte(b,c,d,e,0))===c?m=!1:c=g,m&&(g=a.sepByte(b,c,d,e,1))===c?m=!1:c=g,m&&(g=a.sepByte(b,c,d,e,2))===c?m=!1:c=g);if(!m)return f;e[3]=255;g=a.parseEndparen(b,c,d);return g===c?f:g};a.stringToNumber=function(a,c,d){a=a.substring(c,c+(d-c));return parseFloat(a)};a.stringToPercent=
function(b,c,d){b=a.stringToNumber(b,c,d);return Number.isNaN(b)?-1:0>b?0:100<b?100:b};a.stringToAlpha=function(b,c,d){b=a.stringToNumber(b,c,d);return 0>b?0:1<b?255:255*b};a.stringToHue=function(b,c,d){b=a.stringToNumber(b,c,d);return Number.isNaN(b)||b===Number.POSITIVE_INFINITY||b===Number.NEGATIVE_INFINITY?0:(b%360+360)%360};a.stringToByte=function(b,c,d){b=a.stringToNumber(b,c,d);return 0>b?0:255<b?255:b};a.parseInteger=function(a,c,d,e){var b=!1,g=c;for(e&&c<d&&(43===a.charCodeAt(c)||45===a.charCodeAt(c))&&
++c;c<d&&48<=a.charCodeAt(c)&&57>=a.charCodeAt(c);)++c,b=!0;return b?c:g};a.parseNumber=function(b,c,d){var e=c,f,g=0;if((f=a.parseInteger(b,c,d,!0))!==e)return c=f,c<d&&46===b.charCodeAt(c)?(++c,(f=a.parseInteger(b,c,d,!1))!==c?c<d&&(69===b.charCodeAt(c)||101===b.charCodeAt(c))&&(g=a.parseInteger(b,c+1,d,!0))!==c+1?g:f:c-1):c;c<d&&(43===b.charCodeAt(c)||45===b.charCodeAt(c))&&++c;return c<d&&46===b.charCodeAt(c)&&(++c,(f=a.parseInteger(b,c,d,!1))!==c)?c<d&&(69===b.charCodeAt(c)||101===b.charCodeAt(c))&&
(g=a.parseInteger(b,c+1,d,!0))!==c+1?g:f:e};a.hlsToRgb=a.HlsToRgb=function(a,c,d){c=0>c?0:255<c?255:c;d=0>d?0:255<d?255:d;if(0===d)return[c,c,c];d=127.5>=c?c*(255+d)/255:c+d-c*d/255;var b=2*c-d,f;if(0>a||360<=a)a=(a%360+360)%360;var g=a+120;360<=g&&(g-=360);c=60>g?b+(d-b)*g/60:180>g?d:240>g?b+(d-b)*(240-g)/60:b;g=a;f=60>g?b+(d-b)*g/60:180>g?d:240>g?b+(d-b)*(240-g)/60:b;g=a-120;0>g&&(g+=360);a=60>g?b+(d-b)*g/60:180>g?d:240>g?b+(d-b)*(240-g)/60:b;return[0>c?0:255<c?255:c,0>f?0:255<f?255:f,0>a?0:255<
a?255:a]};a.dehexchar=function(a){return 48<=a&&57>=a?a-48:65<=a&&70>=a?a+10-65:97<=a&&102>=a?a+10-97:-1};a.rgbHex=function(b,c,d){if("undefined"===typeof b||null===b||0===b.length)return!1;var e=b.length,f=[0,0,0,0,0,0,0,0],g=0,h=0;if("#"===b.charAt(0))--e,++g;else if(d)return!1;if(3!==e&&4!==e&&6!==e&&8!==e)return!1;for(d=g;d<b.length;++d){g=a.dehexchar(b.charCodeAt(d));if(0>g)return!1;f[h++]=g}c[3]=4===e?f[3]|f[3]<<4:8===e?f[7]|f[6]<<4:255;3===e||4===e?(c[0]=f[0]|f[0]<<4,c[1]=f[1]|f[1]<<4,c[2]=
f[2]|f[2]<<4):6<=e&&(c[0]=f[1]|f[0]<<4,c[1]=f[3]|f[2]<<4,c[2]=f[5]|f[4]<<4);return!0};a.colorToRgba=a.colorToRgba=function(b){if("undefined"===typeof b||null===b||0===b.length)return null;b=b.replace(/^[\r\n\t \u000c]+|[\r\n\t \u000c]+$/g,"");b=b.toLowerCase();if("transparent"===b)return[0,0,0,0];if("undefined"===typeof b||null===b||0===b.length)return null;var c=[0,0,0,0];if("#"===b.charAt(0)&&a.rgbHex(b,c,!0))return c;if(4<b.length&&"rgb("===b.substring(0,4))return a.rgb(b,4,b.length,c)===b.length?
c:null;if(5<b.length&&"rgba("===b.substring(0,5))return a.rgba(b,5,b.length,c)===b.length?c:null;if(4<b.length&&"hsl("===b.substring(0,4))return a.hsl(b,4,b.length,c)===b.length?c:null;if(5<b.length&&"hsla("===b.substring(0,5))return a.hsla(b,5,b.length,c)===b.length?c:null;var d=a.colorToRgbaSetUpNamedColors();return"undefined"!==typeof d[b]&&null!==d[b]?(a.rgbHex(d[b],c,!1),c):null};a.namedColorMap=a.namedColorMap=null;a.nc="aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4 black 000000 blanchedalmond ffebcd blue 0000ff blueviolet 8a2be2 brown a52a2a burlywood deb887 cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc crimson dc143c cyan 00ffff darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9 darkgreen 006400 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00 darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b darkslategray 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493 deepskyblue 00bfff dimgray 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0 forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 gray 808080 green 008000 greenyellow adff2f honeydew f0fff0 hotpink ff69b4 indianred cd5c5c indigo 4b0082 ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3 lightgreen 90ee90 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa lightskyblue 87cefa lightslategray 778899 lightsteelblue b0c4de lightyellow ffffe0 lime 00ff00 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370d8 mediumseagreen 3cb371 mediumslateblue 7b68ee mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23 orange ffa500 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee palevioletred d87093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f pink ffc0cb plum dda0dd powderblue b0e0e6 purple 800080 rebeccapurple 663399 red ff0000 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513 salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb slateblue 6a5acd slategray 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c teal 008080 thistle d8bfd8 tomato ff6347 turquoise 40e0d0 violet ee82ee wheat f5deb3 white ffffff whitesmoke f5f5f5 yellow ffff00 yellowgreen 9acd32".split(" ");
a.colorToRgbaSetUpNamedColors=function(){if("undefined"===typeof a.namedColorMap||null===a.namedColorMap){for(var b={},c=0;c<a.nc.length;c+=2)b[a.nc[c]]=a.nc[c+1];for(var d="grey gray darkgrey darkgray darkslategrey darkslategray dimgrey dimgray lightgrey lightgray lightslategrey lightslategray slategrey slategray".split(" "),c=0;c<d.length;c+=2)b[d[c]]=b[d[c+1]];a.namedColorMap=b}return a.namedColorMap}})(za);var ua=function(a){a[0]=0>a[0]?0:Math.min(a[0],1);a[1]=0>a[1]?0:Math.min(a[1],1);a[2]=0>
a[2]?0:Math.min(a[2],1);a[3]=0>a[3]?0:Math.min(a[3],1);return a},k={_frustumPoints:function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=[],m=d[1]*f[2],n=d[2]*f[1],k=m-n,l=d[2]*f[0],q=d[0]*f[2],v=l-q,A=d[0]*f[1],p=d[1]*f[0],r=A-p,t=b[2]*d[0],u=b[0]*d[2],x=b[0]*d[1],D=b[1]*d[0],w=f[2]*b[0],F=f[0]*b[2],y=f[0]*b[1],C=f[1]*b[0],E=1/(b[0]*k+b[1]*v+b[2]*r),Ga=f[1]*b[2],Ha=f[2]*b[1],B=b[1]*d[2],z=b[2]*d[1],L=-b[3],U=-d[3],S=-f[3];h[0]=(k*L+(Ga-Ha)*U+(B-z)*S)*E;h[1]=(v*L+(w-F)*U+(t-u)*S)*E;h[2]=(r*
L+(y-C)*U+(x-D)*S)*E;var M=e[1]*f[2],O=e[2]*f[1],H=M-O,T=e[2]*f[0],G=e[0]*f[2],I=T-G,J=e[0]*f[1],P=e[1]*f[0],R=J-P,N=b[2]*e[0],Q=b[0]*e[2],V=b[0]*e[1],W=b[1]*e[0],X=1/(b[0]*H+b[1]*I+b[2]*R),Y=b[1]*e[2],Z=b[2]*e[1],ba=-e[3];h[3]=(H*L+(Ga-Ha)*ba+(Y-Z)*S)*X;h[4]=(I*L+(w-F)*ba+(N-Q)*S)*X;h[5]=(R*L+(y-C)*ba+(V-W)*S)*X;var aa=m-n,ea=l-q,fa=A-p,ga=c[2]*d[0],ha=c[0]*d[2],ia=c[0]*d[1],ja=c[1]*d[0],ka=f[2]*c[0],la=f[0]*c[2],na=f[0]*c[1],oa=f[1]*c[0],ma=1/(c[0]*aa+c[1]*ea+c[2]*fa),pa=f[1]*c[2],qa=f[2]*c[1],
ra=c[1]*d[2],sa=c[2]*d[1],ca=-c[3];h[6]=(aa*ca+(pa-qa)*U+(ra-sa)*S)*ma;h[7]=(ea*ca+(ka-la)*U+(ga-ha)*S)*ma;h[8]=(fa*ca+(na-oa)*U+(ia-ja)*S)*ma;var ta=M-O,ua=T-G,va=J-P,wa=c[2]*e[0],xa=c[0]*e[2],ya=c[0]*e[1],za=c[1]*e[0],Ba=1/(c[0]*ta+c[1]*ua+c[2]*va),Aa=c[1]*e[2],Ia=c[2]*e[1];h[9]=(ta*ca+(pa-qa)*ba+(Aa-Ia)*S)*Ba;h[10]=(ua*ca+(ka-la)*ba+(wa-xa)*S)*Ba;h[11]=(va*ca+(na-oa)*ba+(ya-za)*S)*Ba;var Ja=d[1]*g[2],Ka=d[2]*g[1],La=Ja-Ka,Ma=d[2]*g[0],Na=d[0]*g[2],Oa=Ma-Na,Pa=d[0]*g[1],Qa=d[1]*g[0],Ra=Pa-Qa,Sa=
g[2]*b[0],Ta=g[0]*b[2],Ua=g[0]*b[1],Va=g[1]*b[0],Ca=1/(b[0]*La+b[1]*Oa+b[2]*Ra),Wa=g[1]*b[2],Xa=g[2]*b[1],da=-g[3];h[12]=(La*L+(Wa-Xa)*U+(B-z)*da)*Ca;h[13]=(Oa*L+(Sa-Ta)*U+(t-u)*da)*Ca;h[14]=(Ra*L+(Ua-Va)*U+(x-D)*da)*Ca;var Ya=e[1]*g[2],Za=e[2]*g[1],$a=Ya-Za,ab=e[2]*g[0],bb=e[0]*g[2],cb=ab-bb,db=e[0]*g[1],eb=e[1]*g[0],fb=db-eb,Da=1/(b[0]*$a+b[1]*cb+b[2]*fb);h[15]=($a*L+(Wa-Xa)*ba+(Y-Z)*da)*Da;h[16]=(cb*L+(Sa-Ta)*ba+(N-Q)*da)*Da;h[17]=(fb*L+(Ua-Va)*ba+(V-W)*da)*Da;var gb=Ja-Ka,hb=Ma-Na,ib=Pa-Qa,jb=
g[2]*c[0],kb=g[0]*c[2],lb=g[0]*c[1],mb=g[1]*c[0],Ea=1/(c[0]*gb+c[1]*hb+c[2]*ib),nb=g[1]*c[2],ob=g[2]*c[1];h[18]=(gb*ca+(nb-ob)*U+(ra-sa)*da)*Ea;h[19]=(hb*ca+(jb-kb)*U+(ga-ha)*da)*Ea;h[20]=(ib*ca+(lb-mb)*U+(ia-ja)*da)*Ea;var pb=Ya-Za,qb=ab-bb,rb=db-eb,Fa=1/(c[0]*pb+c[1]*qb+c[2]*rb);h[21]=(pb*ca+(nb-ob)*ba+(Aa-Ia)*da)*Fa;h[22]=(qb*ca+(jb-kb)*ba+(wa-xa)*da)*Fa;h[23]=(rb*ca+(lb-mb)*ba+(ya-za)*da)*Fa;return h},boxCenter:function(a){return[a[0]+.5*(a[3]-a[0]),a[1]+.5*(a[4]-a[1]),a[2]+.5*(a[5]-a[2])]},boxDimensions:function(a){return[a[3]-
a[0],a[4]-a[1],a[5]-a[2]]},boxIsEmpty:function(a){return a[0]>a[3]||a[1]>a[4]||a[2]>a[5]},colorToLinear:function(a){return[.04045>=a[0]?a[0]/12.92:Math.pow((.055+a[0])/1.055,2.4),.04045>=a[1]?a[1]/12.92:Math.pow((.055+a[1])/1.055,2.4),.04045>=a[2]?a[2]/12.92:Math.pow((.055+a[2])/1.055,2.4),3>=a.length?1:a[3]]},colorTosRGB:function(a){return[.0031308>=a[0]?12.92*a[0]:1.055*Math.pow(a[0],1/2.4)-.055,.0031308>=a[1]?12.92*a[1]:1.055*Math.pow(a[1],1/2.4)-.055,.0031308>=a[2]?12.92*a[2]:1.055*Math.pow(a[2],
1/2.4)-.055,3>=a.length?1:a[3]]},frustumHasBox:function(a,b){if(k.boxIsEmpty(b))return!1;for(var c=0;6>c;c++){var d=a[c],e=d[3],f=d[0]*b[0],g=d[2]*b[2],h=d[1]*b[1];if(0>=f+h+g+e&&0>=d[0]*b[3]+d[1]*b[4]+d[2]*b[5]+e&&0>=f+d[1]*b[4]+g+e&&0>=f+d[1]*b[4]+d[2]*b[5]+e&&0>=f+h+d[2]*b[5]+e&&0>=d[0]*b[3]+d[1]*b[4]+g+e&&0>=d[0]*b[3]+h+g+e&&0>=d[0]*b[3]+h+d[2]*b[5]+e)return!1}d=k._frustumPoints(a);for(c=0;3>c;c++){e=b[c];if(d[c]<e&&d[3+c]<e&&d[6+c]<e&&d[9+c]<e&&d[12+c]<e&&d[15+c]<e&&d[18+c]<e&&d[21+c]<e)return!1;
e=b[c+3];if(d[c]>e&&d[3+c]>e&&d[6+c]>e&&d[9+c]>e&&d[12+c]>e&&d[15+c]>e&&d[18+c]>e&&d[21+c]>e)return!1}return!0},frustumHasPoint:function(a,b,c,d){for(var e=0;6>e;e++)if(0>=a[e][0]*b+a[e][1]*c+a[e][2]*d+a[e][3])return!1;return!0},frustumHasSphere:function(a,b,c,d,e){if(0>e)throw Error("radius is negative");for(var f=0;6>f;f++){var g=a[f];if(g[3]+g[0]*b+g[1]*c+g[2]*d<-e)return!1}return!0},mat3copy:function(a){return[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]]},mat3identity:function(){return[1,0,0,
0,1,0,0,0,1]},mat3invert:function(a){var b=[],c=a[4]*a[8]-a[5]*a[7],d=a[5]*a[6]-a[3]*a[8],e=a[3]*a[7]-a[4]*a[6],f=1/(a[0]*c+a[1]*d+a[2]*e);if(0===f)return k.mat3identity();b[0]=c*f;b[1]=(a[2]*a[7]-a[1]*a[8])*f;b[2]=(a[1]*a[5]-a[2]*a[4])*f;b[3]=d*f;b[4]=(a[0]*a[8]-a[2]*a[6])*f;b[5]=(a[2]*a[3]-a[0]*a[5])*f;b[6]=e*f;b[7]=(a[1]*a[6]-a[0]*a[7])*f;b[8]=(a[0]*a[4]-a[1]*a[3])*f;return b},mat3multiply:function(a,b){var c=[];c[0]=b[0]*a[0]+b[1]*a[3]+b[2]*a[6];c[1]=b[0]*a[1]+b[1]*a[4]+b[2]*a[7];c[2]=b[0]*a[2]+
b[1]*a[5]+b[2]*a[8];c[3]=b[3]*a[0]+b[4]*a[3]+b[5]*a[6];c[4]=b[3]*a[1]+b[4]*a[4]+b[5]*a[7];c[5]=b[3]*a[2]+b[4]*a[5]+b[5]*a[8];c[6]=b[6]*a[0]+b[7]*a[3]+b[8]*a[6];c[7]=b[6]*a[1]+b[7]*a[4]+b[8]*a[7];c[8]=b[6]*a[2]+b[7]*a[5]+b[8]*a[8];return c},mat3transform:function(a,b,c,d){var e;"undefined"!==typeof c&&"undefined"!==typeof d?(e=b,b=d):(e=b[0],c=b[1],b=b[2]);return[e*a[0]+c*a[3]+b*a[6],e*a[1]+c*a[4]+b*a[7],e*a[2]+c*a[5]+b*a[8]]},mat3transpose:function(a){return k.mat3transposeInPlace(k.mat3copy(a))},
mat3transposeInPlace:function(a){var b=a[1];a[1]=a[3];a[3]=b;b=a[2];a[2]=a[6];a[6]=b;b=a[5];a[5]=a[7];a[7]=b;return a},mat4copy:function(a){return[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]]},mat4frustum:function(a,b,c,d,e,f){var g=2*e,h=1/(b-a),m=1/(d-c),n=1/(f-e);return[g*h,0,0,0,0,g*m,0,0,(a+b)*h,(d+c)*m,-(f+e)*n,-1,0,0,-(g*f)*n,0]},mat4identity:function(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},mat4inverseTranspose3:function(a){if(0===a[1]&&0===a[2]&&
0===a[4]&&0===a[6]&&0===a[8]&&0===a[9])return 1===a[0]&&1===a[5]&&1===a[10]?[1,0,0,0,1,0,0,0,1]:0!==a[0]*a[5]*a[10]?[1/a[0],0,0,0,1/a[5],0,0,0,1/a[10]]:[1,0,0,0,1,0,0,0,1];a=[a[0],a[1],a[2],a[4],a[5],a[6],a[8],a[9],a[10]];var b=a[0]*a[4]*a[8]+a[3]*a[7]*a[2]+a[6]*a[1]*a[5]-a[6]*a[4]*a[2]-a[3]*a[1]*a[8]-a[0]*a[7]*a[5];if(0===b)return[1,0,0,0,1,0,0,0,1];b=1/b;return[(-a[5]*a[7]+a[4]*a[8])*b,(a[5]*a[6]-a[3]*a[8])*b,(-a[4]*a[6]+a[3]*a[7])*b,(a[2]*a[7]-a[1]*a[8])*b,(-a[2]*a[6]+a[0]*a[8])*b,(a[1]*a[6]-a[0]*
a[7])*b,(-a[2]*a[4]+a[1]*a[5])*b,(a[2]*a[3]-a[0]*a[5])*b,(-a[1]*a[3]+a[0]*a[4])*b]},mat4invert:function(a){var b=a[0]*a[10],c=a[0]*a[11],d=a[0]*a[5],e=a[0]*a[6],f=a[0]*a[7],g=a[0]*a[9],h=a[10]*a[12],m=a[10]*a[13],n=a[10]*a[15],l=a[11]*a[12],K=a[11]*a[13],q=a[11]*a[14],v=a[1]*a[4],A=a[1]*a[6],p=a[1]*a[7],r=a[1]*a[8],t=a[2]*a[4],u=a[2]*a[5],x=a[2]*a[7],D=a[2]*a[8],w=a[2]*a[9],F=a[3]*a[4],y=a[3]*a[5],C=a[3]*a[6],E=a[3]*a[8],B=a[3]*a[9],z=a[4]*a[9],M=a[5]*a[8],O=a[6]*a[8],L=a[6]*a[9],H=a[7]*a[8],S=a[7]*
a[9],G=v-d,I=A-u,J=p-y,T=t-e,d=d-v,A=u-A,u=x-C,v=F-f,p=y-p,x=C-x,e=e-t,t=f-F,f=a[9]*a[12]*x+h*J+l*A+a[8]*a[13]*u+m*v+K*e+a[8]*a[14]*p+a[9]*a[14]*t+q*G+a[8]*a[15]*I+a[9]*a[15]*T+n*d;if(0===f)return k.mat4identity();f=1/f;F=[];F[0]=a[6]*K-a[7]*m+S*a[14]-a[5]*q-L*a[15]+a[5]*n;F[1]=a[3]*m-a[2]*K-B*a[14]+a[1]*q+w*a[15]-a[1]*n;F[2]=a[13]*u+a[14]*p+a[15]*I;F[3]=a[9]*x+a[10]*J+a[11]*A;F[4]=a[7]*h-a[6]*l-H*a[14]+a[4]*q+O*a[15]-a[4]*n;F[5]=a[2]*l-a[3]*h+a[14]*(E-c)+a[15]*(b-D);F[6]=a[12]*x+a[14]*t+a[15]*T;
F[7]=a[8]*u+a[10]*v+a[11]*e;F[8]=a[5]*l-S*a[12]+H*a[13]-a[4]*K+a[15]*(z-M);F[9]=B*a[12]-a[1]*l+a[13]*(c-E)+a[15]*(r-g);F[10]=a[12]*J+a[13]*v+a[15]*d;F[11]=a[8]*p+a[9]*t+a[11]*G;F[12]=L*a[12]-a[5]*h-O*a[13]+a[4]*m+a[14]*(M-z);F[13]=a[1]*h-w*a[12]+a[13]*(D-b)+a[14]*(g-r);F[14]=a[12]*A+a[13]*e+a[14]*G;F[15]=a[8]*I+a[9]*T+a[10]*d;for(a=0;16>a;a++)F[a]*=f;return F},mat4isIdentity:function(a){return 1===a[0]&&0===a[1]&&0===a[2]&&0===a[3]&&0===a[4]&&1===a[5]&&0===a[6]&&0===a[7]&&0===a[8]&&0===a[9]&&1===
a[10]&&0===a[11]&&0===a[12]&&0===a[13]&&0===a[14]&&1===a[15]},mat4lookat:function(a,b,c){if("undefined"===typeof c||null===c)c=[0,1,0];if("undefined"===typeof b||null===b)b=[0,0,0];b=k.vec3sub(b,a);var d=k.vec3length(b);if(1E-6>d)return k.mat4identity();k.vec3scaleInPlace(b,1/d);c=k.vec3normalize(c);c=k.vec3cross(b,c);k.vec3normalizeInPlace(c);d=k.vec3cross(c,b);k.vec3normalizeInPlace(d);k.vec3negateInPlace(b);return[c[0],d[0],b[0],0,c[1],d[1],b[1],0,c[2],d[2],b[2],0,-k.vec3dot(a,c),-k.vec3dot(a,
d),-k.vec3dot(a,b),1]},mat4multiply:function(a,b){for(var c=[],d=0;16>d;d+=4)for(var e=0;4>e;e++)c[d+e]=b[d]*a[e]+b[d+1]*a[e+4]+b[d+2]*a[e+8]+b[d+3]*a[e+12];return c},mat4oblique:function(a,b){var c=(0<=a&&360>a?a:a%360+(0>a?360:0))*k.PiDividedBy180,d=(0<=b&&360>b?b:b%360+(0>b?360:0))*k.PiDividedBy180,e=Math.cos(c),f=Math.cos(d),c=e/(0<=c&&6.283185307179586>c?3.141592653589793>=c?Math.sqrt(1-e*e):-Math.sqrt(1-e*e):Math.sin(c));return[1,0,0,0,0,1,0,0,-f*c,-(0<=d&&6.283185307179586>d?3.141592653589793>=
d?Math.sqrt(1-f*f):-Math.sqrt(1-f*f):Math.sin(d))*c,1,0,0,0,0,1]},mat4ortho:function(a,b,c,d,e,f){var g=1/(b-a),h=1/(d-c),m=1/(f-e);return[2*g,0,0,0,0,2*h,0,0,0,0,-2*m,0,-(a+b)*g,-(d+c)*h,-(e+f)*m,1]},mat4ortho2d:function(a,b,c,d){return k.mat4ortho(a,b,c,d,-1,1)},mat4ortho2dAspect:function(a,b,c,d,e){return k.mat4orthoAspect(a,b,c,d,-1,1,e)},mat4orthoAspect:function(a,b,c,d,e,f,g){g/=Math.abs((b-a)/(d-c));var h=Math.abs(b-a),m=Math.abs(d-c);1>g?(g=m/g,d>c?(c-=.5*(g-m),d+=.5*(g-m)):(d-=.5*(g-m),c+=
.5*(g-m))):(g*=h,b>a?(a-=.5*(g-h),b+=.5*(g-h)):(b-=.5*(g-h),a+=.5*(g-h)));return k.mat4ortho(a,b,c,d,e,f)},mat4perspective:function(a,b,c,d){a=1/Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*k.PiDividedBy360);var e;e=1/(c-d);return[a/b,0,0,0,0,a,0,0,0,0,e*(c+d),-1,0,0,e*c*d*2,0]},mat4perspectiveHorizontal:function(a,b,c,d){return k.mat4perspective(k.Num360DividedByPi*Math.atan2(Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*k.PiDividedBy360),b),b,c,d)},mat4projectVec3:function(a,b,c,d){var e;"undefined"!==
typeof c&&"undefined"!==typeof d?(e=b,b=d):(e=b[0],c=b[1],b=b[2]);d=1/(e*a[3]+c*a[7]+b*a[11]+a[15]);return[(e*a[0]+c*a[4]+b*a[8]+a[12])*d,(e*a[1]+c*a[5]+b*a[9]+a[13])*d,(e*a[2]+c*a[6]+b*a[10]+a[14])*d]},mat4rotate:function(a,b,c,d,e){var f,g;"undefined"!==typeof d&&"undefined"!==typeof e?(f=c,g=d,c=e,e=b):"undefined"===typeof c?(f=b[0],g=b[1],c=b[2],e=b[3]):(f=c[0],g=c[1],c=c[2],e=b);e=(0<=e&&360>e?e:e%360+(0>e?360:0))*k.PiDividedBy180;b=Math.cos(e);var h=3.141592653589793>=e?Math.sqrt(1-b*b):-Math.sqrt(1-
b*b);if(1===f&&0===g&&0===c)return[a[0],a[1],a[2],a[3],b*a[4]+a[8]*h,b*a[5]+a[9]*h,b*a[6]+a[10]*h,b*a[7]+a[11]*h,b*a[8]-h*a[4],b*a[9]-h*a[5],b*a[10]-h*a[6],b*a[11]-h*a[7],a[12],a[13],a[14],a[15]];if(0===f&&1===g&&0===c)return[b*a[0]-h*a[8],b*a[1]-h*a[9],b*a[2]-h*a[10],b*a[3]-h*a[11],a[4],a[5],a[6],a[7],b*a[8]+a[0]*h,b*a[9]+a[1]*h,b*a[10]+a[2]*h,b*a[11]+a[3]*h,a[12],a[13],a[14],a[15]];if(0===f&&0===g&&1===c)return[b*a[0]+a[4]*h,b*a[1]+a[5]*h,b*a[2]+a[6]*h,b*a[3]+a[7]*h,b*a[4]-h*a[0],b*a[5]-h*a[1],
b*a[6]-h*a[2],b*a[7]-h*a[3],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]];if(0===f&&0===g&&0===c)return k.mat4copy(a);e=1/Math.sqrt(f*f+g*g+c*c);f*=e;g*=e;c*=e;var m=g*g;d=1-b;var n=f*g,l=g*c;e=f*h;g*=h;var K=c*h,h=d*l,q=d*n,v=d*f*c;f=b+d*f*f;n=q+K;l=v-g;m=b+d*m;K=q-K;q=h+e;c=b+d*c*c;b=v+g;e=h-e;return[a[0]*f+a[4]*n+a[8]*l,a[1]*f+a[5]*n+a[9]*l,a[10]*l+a[2]*f+a[6]*n,a[11]*l+a[3]*f+a[7]*n,a[0]*K+a[4]*m+a[8]*q,a[1]*K+a[5]*m+a[9]*q,a[10]*q+a[2]*K+a[6]*m,a[11]*q+a[3]*K+a[7]*m,a[0]*b+a[4]*e+a[8]*c,a[1]*
b+a[5]*e+a[9]*c,a[10]*c+a[2]*b+a[6]*e,a[11]*c+a[3]*b+a[7]*e,a[12],a[13],a[14],a[15]]},mat4rotated:function(a,b,c,d){var e;"undefined"!==typeof c&&"undefined"!==typeof d?(e=b,b=d,d=a):"undefined"===typeof b?(e=a[0],c=a[1],b=a[2],d=a[3]):(e=b[0],c=b[1],b=b[2],d=a);d=(0<=d&&360>d?d:d%360+(0>d?360:0))*k.PiDividedBy180;if(90===d||-270===d)return d=1/Math.sqrt(e*e+c*c+b*b),e*=d,c*=d,b*=d,[e*e,e*c+b,e*b-c,0,c*e-b,c*c,c*b+e,0,b*e+c,b*c-e,b*b,0,0,0,0,1];if(-90===d||270===d)return d=1/Math.sqrt(e*e+c*c+b*b),
e*=d,c*=d,b*=d,[e*e,e*c-b,e*b+c,0,c*e+b,c*c,c*b-e,0,b*e-c,b*c+e,b*b,0,0,0,0,1];if(180===d||-180===d)return d=1/Math.sqrt(e*e+c*c+b*b),e*=d,c*=d,b*=d,[e*e*2-1,e*c*2,e*b*2,0,c*e*2,c*c*2-1,c*b*2,0,b*e*2,b*c*2,b*b*2-1,0,0,0,0,1];a=Math.cos(d);var f=0<=d&&6.283185307179586>d?3.141592653589793>=d?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(d);if(1===e&&0===c&&0===b)return[1,0,0,0,0,a,f,0,0,-f,a,0,0,0,0,1];if(0===e&&1===c&&0===b)return[a,0,-f,0,0,1,0,0,f,0,a,0,0,0,0,1];if(0===e&&0===c&&1===b)return[a,f,
0,0,-f,a,0,0,0,0,1,0,0,0,0,1];if(0===e&&0===c&&0===b)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];d=1/Math.sqrt(e*e+c*c+b*b);e*=d;c*=d;b*=d;d=e*e;var g=c*c,h=b*b,m=e*b,n=c*b,l=e*f,K=c*f,f=b*f,q=1-a;e=q*e*c;c=q*m;b=q*n;return[a+q*d,e+f,c-K,0,e-f,a+q*g,b+l,0,c+K,b-l,a+q*h,0,0,0,0,1]},mat4scale:function(a,b,c,d){var e;"undefined"!==typeof c&&"undefined"!==typeof d?(e=b,b=d):(e=b[0],c=b[1],b=b[2]);return[a[0]*e,a[1]*e,a[2]*e,a[3]*e,a[4]*c,a[5]*c,a[6]*c,a[7]*c,a[8]*b,a[9]*b,a[10]*b,a[11]*b,a[12],a[13],a[14],
a[15]]},mat4scaleInPlace:function(a,b,c,d){var e;"undefined"!==typeof c&&"undefined"!==typeof d?(e=b,b=d):(e=b[0],c=b[1],b=b[2]);a[0]*=e;a[1]*=e;a[2]*=e;a[3]*=e;a[4]*=c;a[5]*=c;a[6]*=c;a[7]*=c;a[8]*=b;a[9]*=b;a[10]*=b;a[11]*=b;return a},mat4scaled:function(a,b,c){return"undefined"!==typeof b&&"undefined"!==typeof c?[a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1]:[a[0],0,0,0,0,a[1],0,0,0,0,a[2],0,0,0,0,1]},mat4toFrustumPlanes:function(a){var b=[[],[],[],[],[],[]];b[0]=k.planeNormalizeInPlace([a[3]+a[0],a[7]+a[4],
a[11]+a[8],a[15]+a[12]]);b[1]=k.planeNormalizeInPlace([a[3]-a[0],a[7]-a[4],a[11]-a[8],a[15]-a[12]]);b[2]=k.planeNormalizeInPlace([a[3]-a[1],a[7]-a[5],a[11]-a[9],a[15]-a[13]]);b[3]=k.planeNormalizeInPlace([a[3]+a[1],a[7]+a[5],a[11]+a[9],a[15]+a[13]]);b[4]=k.planeNormalizeInPlace([a[3]+a[2],a[7]+a[6],a[11]+a[10],a[15]+a[14]]);b[5]=k.planeNormalizeInPlace([a[3]-a[2],a[7]-a[6],a[11]-a[10],a[15]-a[14]]);return b},mat4toMat3:function(a){return[a[0],a[1],a[2],a[4],a[5],a[6],a[8],a[9],a[10]]},mat4transform:function(a,
b,c,d,e){var f;"undefined"!==typeof c&&"undefined"!==typeof d&&"undefined"!==typeof e?(f=b,b=e):(f=b[0],c=b[1],d=b[2],b=b[3]);return[f*a[0]+c*a[4]+d*a[8]+b*a[12],f*a[1]+c*a[5]+d*a[9]+b*a[13],f*a[2]+c*a[6]+d*a[10]+b*a[14],f*a[3]+c*a[7]+d*a[11]+b*a[15]]},mat4transformVec3:function(a,b,c,d){var e;"undefined"!==typeof c&&"undefined"!==typeof d?(e=b,b=d):(e=b[0],c=b[1],b=b[2]);return[e*a[0]+c*a[4]+b*a[8]+a[12],e*a[1]+c*a[5]+b*a[9]+a[13],e*a[2]+c*a[6]+b*a[10]+a[14]]},mat4translate:function(a,b,c,d){var e;
"undefined"!==typeof c&&"undefined"!==typeof d?(e=b,b=d):(e=b[0],c=b[1],b=b[2]);return[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[0]*e+a[4]*c+a[8]*b+a[12],a[1]*e+a[5]*c+a[9]*b+a[13],a[2]*e+a[6]*c+a[10]*b+a[14],a[3]*e+a[7]*c+a[11]*b+a[15]]},mat4translated:function(a,b,c){var d;"undefined"!==typeof b&&"undefined"!==typeof c?(d=a,a=c):(d=a[0],b=a[1],a=a[2]);return[1,0,0,0,0,1,0,0,0,0,1,0,d,b,a,1]},mat4transpose:function(a){return k.mat4transposeInPlace(k.mat4copy(a))},mat4transposeInPlace:function(a){var b=
a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return a},planeFromNormalAndPoint:function(a,b){return[a[0],a[1],a[2],-(a[0]*b[0]+a[1]*b[1]+a[2]*b[2])]},planeNormalize:function(a){return k.planeNormalizeInPlace(k.vec4copy(a))},planeNormalizeInPlace:function(a){var b=a[0],c=a[1],d=a[2],b=Math.sqrt(b*b+c*c+d*d);0!==b&&(b=1/b,a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b);return a},quatConjugate:function(a){return[-a[0],
-a[1],-a[2],a[3]]},quatFromAxisAngle:function(a,b,c,d){var e;"undefined"!==typeof c&&"undefined"!==typeof d?(e=b,b=d):"undefined"===typeof b?(e=a[0],c=a[1],b=a[2]):(e=b[0],c=b[1],b=b[2]);d=(0<=a&&360>a?a:a%360+(0>a?360:0))*k.PiDividedBy360;a=Math.cos(d);d=0<=d&&6.283185307179586>d?3.141592653589793>=d?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(d);e=k.vec3normalizeInPlace([e,c,b]);e=[e[0],e[1],e[2],a];e[0]*=d;e[1]*=d;e[2]*=d;return e},quatFromMat4:function(a){var b=[],c=a[1],d=a[2],e=a[4],f=a[6],
g=a[8],h=a[9],m=a[0]+a[5]+a[10];0<=m?(a=.5*Math.sqrt(m+1),m=.25/a,b[0]=(f-h)*m,b[1]=(g-d)*m,b[2]=(c-e)*m,b[3]=a):a[0]>a[5]&&a[0]>a[10]?(a=.5*Math.sqrt(1+a[0]-a[5]-a[10]),m=.25/a,b[0]=a,b[1]=(e+c)*m,b[2]=(d+g)*m,b[3]=(f-h)*m):a[5]>a[10]?(a=.5*Math.sqrt(1+a[5]-a[0]-a[10]),m=.25/a,b[0]=(e+c)*m,b[1]=a,b[2]=(h+f)*m,b[3]=(g-d)*m):(a=.5*Math.sqrt(1+a[10]-a[0]-a[5]),m=.25/a,b[0]=(g+d)*m,b[1]=(h+f)*m,b[2]=a,b[3]=(c-e)*m);return b},quatFromTaitBryan:function(a,b,c,d){var e,f;if("undefined"===typeof d||null===
d)d=k.GlobalRollPitchYaw;if(0>d||6<=d)throw Error("invalid mode");a.constructor===Array?(c=(0<=a[2]&&360>a[2]?a[2]:a[2]%360+(0>a[2]?360:0))*k.PiDividedBy360,e=(0<=a[0]&&360>a[0]?a[0]:a[0]%360+(0>a[0]?360:0))*k.PiDividedBy360,f=(0<=a[1]&&360>a[1]?a[1]:a[1]%360+(0>a[1]?360:0))*k.PiDividedBy360):(c=(0<=c&&360>c?c:c%360+(0>c?360:0))*k.PiDividedBy360,e=(0<=a&&360>a?a:a%360+(0>a?360:0))*k.PiDividedBy360,f=(0<=b&&360>b?b:b%360+(0>b?360:0))*k.PiDividedBy360);a=Math.cos(e);e=0<=e&&6.283185307179586>e?3.141592653589793>=
e?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(e);b=Math.cos(f);f=0<=f&&6.283185307179586>f?3.141592653589793>=f?Math.sqrt(1-b*b):-Math.sqrt(1-b*b):Math.sin(f);var g=Math.cos(c);c=0<=c&&6.283185307179586>c?3.141592653589793>=c?Math.sqrt(1-g*g):-Math.sqrt(1-g*g):Math.sin(c);var h;d===k.GlobalPitchYawRoll||d===k.GlobalPitchRollYaw?(h=[c*f,g*f,c*b,g*b],d===k.GlobalPitchYawRoll&&(h[0]=-h[0]),d=[h[3]*e+h[0]*a,h[1]*a+h[2]*e,h[2]*a-h[1]*e,h[3]*a-h[0]*e]):d===k.GlobalYawPitchRoll||d===k.GlobalYawRollPitch?
(h=[g*e,c*e,c*a,g*a],d===k.GlobalYawRollPitch&&(h[1]=-h[1]),d=[h[0]*b-h[2]*f,h[3]*f+h[1]*b,h[2]*b+h[0]*f,h[3]*b-h[1]*f]):(h=[b*e,f*a,f*e,b*a],d===k.GlobalRollPitchYaw&&(h[2]=-h[2]),d=[h[0]*g+h[1]*c,h[1]*g-h[0]*c,h[3]*c+h[2]*g,h[3]*g-h[2]*c]);return d},quatFromVectors:function(a,b){var c=k.vec3cross(a,b);if(1E-9>k.vec3dot(c,c)){if(0<k.vec3dot(a,b))return[0,0,0,1];c=k.vec3perp(a);c[3]=0}else{var d=k.vec3length(a)*k.vec3length(b);0===d&&(d=1);c[3]=d+k.vec3dot(a,b)}return k.quatNormalizeInPlace(c)},quatIdentity:function(){return[0,
0,0,1]},quatInvert:function(a){var b=1/k.quatDot(a,a);return k.vec4scaleInPlace(k.quatConjugate(a),b)},quatIsIdentity:function(a){return 0===a[0]&&0===a[1]&&0===a[2]&&1===a[3]},quatMultiply:function(a,b){return[a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],a[3]*b[1]+a[1]*b[3]+a[2]*b[0]-a[0]*b[2],a[3]*b[2]+a[2]*b[3]+a[0]*b[1]-a[1]*b[0],a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2]]},quatNlerp:function(a,b,c){var d=1-c,e=a[0]*d,f=a[1]*d,g=a[2]*d,d=a[3]*d,h=b[0]*c,m=b[1]*c,n=b[2]*c;c*=b[3];return 0>a[0]*b[0]+a[1]*
b[1]+a[2]*b[2]+a[3]*b[3]?k.quatNormalizeInPlace([e-h,f-m,g-n,d-c]):k.quatNormalizeInPlace([e+h,f+m,g+n,d+c])},quatRotate:function(a,b,c,d,e){return k.quatMultiply(a,k.quatFromAxisAngle(b,c,d,e))},quatSlerp:function(a,b,c){var d=k.quatDot(a,b),e=b;0>d&&(e=[-b[0],-b[1],-b[2],-b[3]],d=k.quatDot(a,e));if(-1<d)if(1>d){if(d=Math.acos(d),0===d)return k.quatNlerp(a,b,c)}else return k.quatNlerp(a,b,c);else d=Math.PI;var f=1/Math.sin(d);b=Math.sin((1-c)*d)*f;c=Math.sin(c*d)*f;return[a[0]*b+e[0]*c,a[1]*b+e[1]*
c,a[2]*b+e[2]*c,a[3]*b+e[3]*c]},quatToAxisAngle:function(a){var b=a[3],c=1-b*b;return 0<c?(c=1/Math.sqrt(c),[a[0]*c,a[1]*c,a[2]*c,Math.acos(Math.min(1,Math.max(0,b)))*k.Num360DividedByPi]):[0,1,0,0]},quatToMat4:function(a){var b,c,d,e,f,g,h,m,n;b=2*a[0];c=2*a[1];d=2*a[2];e=b*a[0];f=b*a[1];g=b*a[2];h=c*a[1];m=d*a[1];n=d*a[2];b*=a[3];c*=a[3];a=d*a[3];return[1-(h+n),f+a,g-c,0,f-a,1-(e+n),m+b,0,g+c,m-b,1-(e+h),0,0,0,0,1]},quatToTaitBryan:function(a,b){var c=a[3],d,e,f,g=1;if("undefined"===typeof b||null===
b)b=k.GlobalRollPitchYaw;if(0>b||6<=b)throw Error("invalid mode");b===k.GlobalRollPitchYaw?(d=a[1],e=a[0],f=a[2],g=-1):b===k.GlobalPitchYawRoll?(d=a[2],e=a[1],f=a[0],g=-1):b===k.GlobalPitchRollYaw?(d=a[1],e=a[2],f=a[0]):b===k.GlobalYawPitchRoll?(d=a[2],e=a[0],f=a[1]):b===k.GlobalYawRollPitch?(d=a[0],e=a[2],f=a[1],g=-1):(d=a[0],e=a[1],f=a[2]);var h=e*e,m=Math.atan2(2*(c*d-g*e*f),1-2*(d*d+h)),n=2*(c*e+g*d*f);1<n&&(n=1);-1>n&&(n=-1);n=Math.asin(n);e=Math.atan2(2*(c*f-g*d*e),1-2*(h+f*f));m*=k.Num180DividedByPi;
n*=k.Num180DividedByPi;e*=k.Num180DividedByPi;if(1E-6>Math.abs(n-90)||1E-6>Math.abs(n+90))e=0,m=Math.atan2(d,c)*k.Num180DividedByPi,isNaN(m)&&(m=0);c=[];b===k.GlobalRollPitchYaw?(c[0]=n,c[1]=m,c[2]=e):b===k.GlobalPitchYawRoll?(c[0]=e,c[1]=n,c[2]=m):b===k.GlobalPitchRollYaw?(c[0]=e,c[1]=m,c[2]=n):b===k.GlobalYawPitchRoll?(c[0]=n,c[1]=e,c[2]=m):b===k.GlobalYawRollPitch?(c[0]=m,c[1]=e,c[2]=n):(c[0]=m,c[1]=n,c[2]=e);return c},quatTransform:function(a,b){var c=a[1]*b[2]-a[2]*b[1]+b[0]*a[3],d=a[2]*b[0]-
a[0]*b[2]+b[1]*a[3],e=a[0]*b[1]-a[1]*b[0]+b[2]*a[3],f=a[0]*b[0]+a[1]*b[1]+a[2]*b[2];return 3===b.length?[c*a[3]-(d*a[2]-e*a[1])+a[0]*f,d*a[3]-(e*a[0]-c*a[2])+a[1]*f,e*a[3]-(c*a[1]-d*a[0])+a[2]*f]:[c*a[3]-(d*a[2]-e*a[1])+a[0]*f,d*a[3]-(e*a[0]-c*a[2])+a[1]*f,e*a[3]-(c*a[1]-d*a[0])+a[2]*f,1]},vec2abs:function(a){return[Math.abs(a[0]),Math.abs(a[1])]},vec2absInPlace:function(a){a[0]=Math.abs(a[0]);a[1]=Math.abs(a[1]);return a},vec2add:function(a,b){return[a[0]+b[0],a[1]+b[1]]},vec2addInPlace:function(a,
b){var c=b[1];a[0]+=b[0];a[1]+=c;return a},vec2assign:function(a,b){a[0]=b[0];a[1]=b[1];return a},vec2clamp:function(a,b,c){return k.vec2clampInPlace(k.vec2copy(a),b,c)},vec2clampInPlace:function(a,b,c){var d=Math.min(c,Math.max(b,a[1]));a[0]=Math.min(c,Math.max(b,a[0]));a[1]=d;return a},vec2copy:function(a){return[a[0],a[1]]},vec2dist:function(a,b){return k.vec2length(k.vec2sub(a,b))},vec2dot:function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2length:function(a){var b=a[0];a=a[1];return Math.sqrt(b*b+
a*a)},vec2lerp:function(a,b,c){return[a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c]},vec2mul:function(a,b){return[a[0]*b[0],a[1]*b[1]]},vec2mulInPlace:function(a,b){var c=b[1];a[0]*=b[0];a[1]*=c;return a},vec2negate:function(a){return[-a[0],-a[1]]},vec2negateInPlace:function(a){a[0]=-a[0];a[1]=-a[1];return a},vec2normalize:function(a){return k.vec2normalizeInPlace([a[0],a[1]])},vec2normalizeInPlace:function(a){var b=a[0],c=a[1],b=Math.sqrt(b*b+c*c);0!==b&&(b=1/b,a[0]*=b,a[1]*=b);return a},vec2perp:function(a){return[-a[1],
a[0]]},vec2proj:function(a,b){var c=k.vec2dot(b,b);return 0===c?[0,0]:k.vec2scale(b,k.vec2dot(a,b)/c)},vec2reflect:function(a,b){return k.vec2sub(a,k.vec2scale(b,2*k.vec2dot(b,a)))},vec2scale:function(a,b){return k.vec2scaleInPlace([a[0],a[1]],b)},vec2scaleInPlace:function(a,b){a[0]*=b;a[1]*=b;return a},vec2sub:function(a,b){return[a[0]-b[0],a[1]-b[1]]},vec2subInPlace:function(a,b){var c=b[1];a[0]-=b[0];a[1]-=c;return a},vec3abs:function(a){return[Math.abs(a[0]),Math.abs(a[1]),Math.abs(a[2])]},vec3absInPlace:function(a){a[0]=
Math.abs(a[0]);a[1]=Math.abs(a[1]);a[2]=Math.abs(a[2]);return a},vec3add:function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2]]},vec3addInPlace:function(a,b){var c=b[1],d=b[2];a[0]+=b[0];a[1]+=c;a[2]+=d;return a},vec3assign:function(a,b){a[0]=b[0];a[1]=b[1];a[2]=b[2];return a},vec3clamp:function(a,b,c){return k.vec3clampInPlace(k.vec3copy(a),b,c)},vec3clampInPlace:function(a,b,c){var d=Math.min(c,Math.max(b,a[1])),e=Math.min(c,Math.max(b,a[2]));a[0]=Math.min(c,Math.max(b,a[0]));a[1]=d;a[2]=e;return a},
vec3copy:function(a){return[a[0],a[1],a[2]]},vec3cross:function(a,b){return[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]},vec3dist:function(a,b){return k.vec3length(k.vec3sub(a,b))},vec3dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3fromWindowPoint:function(a,b,c,d){var e=.5*c[2],f=.5*c[3],g=0,h=0,m=2*a[2]-1;0!==e&&0!==f&&(g=(a[0]-c[0]-e)/e,h=(a[1]-c[1]-f)/f);h=d?h:-h;a=k.mat4invert(b);return k.mat4projectVec3(a,[g,h,m])},vec3length:function(a){var b=a[0],c=a[1];a=a[2];
return Math.sqrt(b*b+c*c+a*a)},vec3lerp:function(a,b,c){return[a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c,a[2]+(b[2]-a[2])*c]},vec3mul:function(a,b){return[a[0]*b[0],a[1]*b[1],a[2]*b[2]]},vec3mulInPlace:function(a,b){var c=b[1],d=b[2];a[0]*=b[0];a[1]*=c;a[2]*=d;return a},vec3negate:function(a){return[-a[0],-a[1],-a[2]]},vec3negateInPlace:function(a){a[0]=-a[0];a[1]=-a[1];a[2]=-a[2];return a},vec3normalize:function(a){return k.vec3normalizeInPlace([a[0],a[1],a[2]])},vec3normalizeInPlace:function(a){var b=
a[0],c=a[1],d=a[2],b=Math.sqrt(b*b+c*c+d*d);0!==b&&(b=1/b,a[0]*=b,a[1]*=b,a[2]*=b);return a},vec3perp:function(a){var b=Math.abs(a[0]),c=Math.abs(a[1]),d=Math.max(b,c,Math.abs(a[2])),e=[0,0,0];d===b?(e[0]=a[1],e[1]=-a[0],e[2]=0):d===c?(e[0]=0,e[1]=a[2],e[2]=-a[1]):(e[0]=-a[2],e[1]=0,e[2]=a[0]);return e},vec3proj:function(a,b){var c=k.vec3dot(b,b);return 0===c?[0,0,0]:k.vec3scale(b,k.vec3dot(a,b)/c)},vec3reflect:function(a,b){return k.vec3sub(a,k.vec3scale(b,2*k.vec3dot(b,a)))},vec3scale:function(a,
b){return k.vec3scaleInPlace([a[0],a[1],a[2]],b)},vec3scaleInPlace:function(a,b){a[0]*=b;a[1]*=b;a[2]*=b;return a},vec3sub:function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]},vec3subInPlace:function(a,b){var c=b[1],d=b[2];a[0]-=b[0];a[1]-=c;a[2]-=d;return a},vec3toWindowPoint:function(a,b,c,d){if(0>c[2]||0>c[3])throw Error();a=k.mat4projectVec3(b,a);b=.5*c[2];var e=.5*c[3];return[a[0]*b+b+c[0],(d?a[1]:-a[1])*e+e+c[1],.5*(a[2]+1)]},vec3triple:function(a,b,c){return k.vec3dot(a,k.vec3cross(b,c))},
vec4abs:function(a){return[Math.abs(a[0]),Math.abs(a[1]),Math.abs(a[2]),Math.abs(a[3])]},vec4absInPlace:function(a){a[0]=Math.abs(a[0]);a[1]=Math.abs(a[1]);a[2]=Math.abs(a[2]);a[3]=Math.abs(a[3]);return a},vec4add:function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2],a[3]+b[3]]},vec4addInPlace:function(a,b){var c=b[1],d=b[2],e=b[3];a[0]+=b[0];a[1]+=c;a[2]+=d;a[3]+=e;return a},vec4assign:function(a,b){a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3];return a},vec4clamp:function(a,b,c){return k.vec4clampInPlace(k.vec4copy(a),
b,c)},vec4clampInPlace:function(a,b,c){var d=Math.min(c,Math.max(b,a[1])),e=Math.min(c,Math.max(b,a[2])),f=Math.min(c,Math.max(b,a[3]));a[0]=Math.min(c,Math.max(b,a[0]));a[1]=d;a[2]=e;a[3]=f;return a},vec4copy:function(a){return[a[0],a[1],a[2],a[3]]},vec4dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4length:function(a){var b=a[0],c=a[1],d=a[2];a=a[3];return Math.sqrt(b*b+c*c+d*d+a*a)},vec4lerp:function(a,b,c){return[a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c,a[2]+(b[2]-a[2])*c,a[3]+
(b[3]-a[3])*c]},vec4negate:function(a){return[-a[0],-a[1],-a[2],-a[3]]},vec4negateInPlace:function(a){a[0]=-a[0];a[1]=-a[1];a[2]=-a[2];a[3]=-a[3];return a},vec4normalize:function(a){return k.vec4normalizeInPlace([a[0],a[1],a[2],a[3]])},vec4normalizeInPlace:function(a){var b=a[0],c=a[1],d=a[2],e=a[3],b=Math.sqrt(b*b+c*c+d*d+e*e);0!==b&&(b=1/b,a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b);return a},vec4proj:function(a,b){var c=k.vec4dot(b,b);return 0===c?[0,0,0]:k.vec4scale(b,k.vec4dot(a,b)/c)},vec4scale:function(a,
b){return[a[0]*b,a[1]*b,a[2]*b,a[3]*b]},vec4scaleInPlace:function(a,b){a[0]*=b;a[1]*=b;a[2]*=b;a[3]*=b;return a},vec4sub:function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2],a[3]-b[3]]},vec4subInPlace:function(a,b){var c=b[1],d=b[2],e=b[3];a[0]-=b[0];a[1]-=c;a[2]-=d;a[3]-=e;return a}};k.quatDot=k.vec4dot;k.quatNormalizeInPlace=k.vec4normalizeInPlace;k.quatNormalize=k.vec4normalize;k.quatLength=k.vec4length;k.quatScaleInPlace=k.vec4scaleInPlace;k.quatScale=k.vec4scale;k.quatCopy=k.vec4copy;k.PiTimes2=
6.283185307179586;k.HalfPi=1.5707963267948966;k.PiDividedBy180=.017453292519943295;k.ToRadians=k.PiDividedBy180;k.PiDividedBy360=.008726646259971648;k.Num360DividedByPi=114.59155902616465;k.Num180DividedByPi=57.29577951308232;k.ToDegrees=k.Num180DividedByPi;k.GlobalPitchYawRoll=0;k.GlobalPitchRollYaw=1;k.GlobalYawPitchRoll=2;k.GlobalYawRollPitch=3;k.GlobalRollPitchYaw=4;k.GlobalRollYawPitch=5;k.LocalPitchYawRoll=k.GlobalRollYawPitch;k.LocalPitchRollYaw=k.GlobalYawRollPitch;k.LocalYawPitchRoll=k.GlobalRollPitchYaw;
k.LocalYawRollPitch=k.GlobalPitchRollYaw;k.LocalRollPitchYaw=k.GlobalYawPitchRoll;k.LocalRollYawPitch=k.GlobalPitchYawRoll;k.PitchYawRoll=0;k.PitchRollYaw=1;k.YawPitchRoll=2;k.YawRollPitch=3;k.RollPitchYaw=4;k.RollYawPitch=5;k.quatInverse=k.quatInvert;k.vec3norm=k.vec3normalize;k.vec4norm=k.vec4normalize;k.quatNorm=k.quatNormalize;k.vec3normInPlace=k.vec3normalizeInPlace;k.vec4normInPlace=k.vec4normalizeInPlace;k.quatNormInPlace=k.quatNormalizeInPlace;k.planeNormInPlace=k.planeNormalizeInPlace;k.planeNorm=
k.planeNormalize;p=function(a){var b=a;"function"===typeof a.getContext&&(b=HTMLCanvasElement&&b.constructor===HTMLCanvasElement?H3DU.get3DContext(a):b&&b.getContext?b.getContext():b);this.context=b;this.textureCache={};this._textureLoader=new H3DU.TextureLoader;this._meshLoader=new H3DU.BufferedMesh._MeshLoader;this._renderedOutsideScene=!1;this.shapes=[];this._errors=!1;this._frontFace=H3DU.Scene3D.CCW;this._cullFace=H3DU.Scene3D.NONE;this.clearColor=[0,0,0,1];this.fboFilter=null;this._subScene=
new H3DU.Batch3D;this._subScene.getLights().setBasic();this._programs=new H3DU.Scene3D.ProgramCache;this.useDevicePixelRatio=!1;this._is3d=H3DU.is3DContext(this.context);this._pixelRatio=1;this.autoResize=!0;this.width=Math.ceil(1*this.context.canvas.clientWidth);this.height=Math.ceil(1*this.context.canvas.clientHeight);this.context.canvas.width=this.width;this.context.canvas.height=this.height;this._is3d&&(this.context.viewport(0,0,this.width,this.height),this.context.enable(this.context.BLEND),
this.context.blendFunc(this.context.SRC_ALPHA,this.context.ONE_MINUS_SRC_ALPHA),this.context.enable(this.context.DEPTH_TEST),this.context.depthFunc(this.context.LEQUAL),this.context.disable(this.context.CULL_FACE),this.context.clearDepth(1),this._setClearColor(),this._setFace())};p.prototype.getCanvas=function(){return this.context?this.context.canvas:null};p.LIGHTING_ENABLED=1;p.SPECULAR_MAP_ENABLED=2;p.NORMAL_MAP_ENABLED=4;p.SPECULAR_ENABLED=8;p.TEXTURE_ENABLED=16;p.COLORATTR_ENABLED=32;p.ROUGHNESS_ENABLED=
64;p.ROUGHNESS_MAP_ENABLED=128;p.METALNESS_ENABLED=256;p.METALNESS_MAP_ENABLED=512;p.PHYSICAL_BASED_ENABLED=1024;p.INVERT_ROUGHNESS_ENABLED=2048;p.ENV_MAP_ENABLED=4096;p.ENV_EQUIRECT_ENABLED=8192;p.EMISSION_MAP_ENABLED=16384;p.OCCLUSION_MAP_ENABLED=32768;p._flagsForShape=function(a){var b=0,c=a.material;"undefined"!==typeof c&&null!==c&&c instanceof H3DU.Material&&(b|=H3DU.Scene3D.LIGHTING_ENABLED,b|=0!==c.specular[0]||0!==c.specular[1]||0!==c.specular[2]?H3DU.Scene3D.SPECULAR_ENABLED:0,b|=c.specularMap?
H3DU.Scene3D.SPECULAR_MAP_ENABLED:0,b|=c.normalMap?H3DU.Scene3D.NORMAL_MAP_ENABLED:0,b|=c.texture?H3DU.Scene3D.TEXTURE_ENABLED:0,b|=c.occlusionMap?H3DU.Scene3D.OCCLUSION_MAP_ENABLED:0,b|=c.emissionMap?H3DU.Scene3D.EMISSION_MAP_ENABLED:0);"undefined"!==typeof c&&null!==c&&c instanceof H3DU.PbrMaterial&&(b|=H3DU.Scene3D.LIGHTING_ENABLED|H3DU.Scene3D.PHYSICAL_BASED_ENABLED,c.workflow===H3DU.PbrMaterial.Metallic?(b|="number"===typeof c.metalness?H3DU.Scene3D.METALNESS_ENABLED:0,b|=c.metalnessMap?H3DU.Scene3D.METALNESS_MAP_ENABLED:
0):(b|=c.specular?H3DU.Scene3D.SPECULAR_ENABLED:0,b|=c.specularMap?H3DU.Scene3D.SPECULAR_MAP_ENABLED:0),b|=c.normalMap?H3DU.Scene3D.NORMAL_MAP_ENABLED:0,b|=c.occlusionMap?H3DU.Scene3D.OCCLUSION_MAP_ENABLED:0,b|=c.emissionMap?H3DU.Scene3D.EMISSION_MAP_ENABLED:0,b|=c.albedoMap?H3DU.Scene3D.TEXTURE_ENABLED:0,b|=!0===c.invertRoughness?H3DU.Scene3D.INVERT_ROUGHNESS_ENABLED:0,b|="number"===typeof c.roughness?H3DU.Scene3D.ROUGHNESS_ENABLED:0,b|=c.roughnessMap?H3DU.Scene3D.ROUGHNESS_MAP_ENABLED:0,"undefined"!==
typeof c.environmentMap&&null!==c.environmentMap&&(b=c.environmentMap instanceof H3DU.CubeMap?b|H3DU.Scene3D.ENV_MAP_ENABLED:b|H3DU.Scene3D.ENV_EQUIRECT_ENABLED));a=a.getMeshBuffer();"undefined"!==typeof a&&null!==a&&(a=a.getAttribute(H3DU.Semantic.COLOR),"undefined"!==typeof a&&null!==a&&(b|=H3DU.Scene3D.COLORATTR_ENABLED));return b};p.ProgramCache=function(){this._programs=[];this._customPrograms=[]};p.ProgramCache.prototype.dispose=function(){var a,b;for(a=0;a<this._customPrograms.length;a++)b=
this._customPrograms[a],b[2].dispose();for(a=0;a<this._programs.length;a++)(b=this._programs[a])&&b.dispose();this._customPrograms=[];this._programs=[]};p.ProgramCache.prototype.getCustomProgram=function(a,b){if(!b)throw Error();if(!H3DU.is3DContext(b))return null;if(a instanceof H3DU.ShaderProgram)return a;for(var c=0;c<this._customPrograms.length;c++){var d=this._customPrograms[c];if(d[0]===a&&d[1]===b)return d[2]._update(),d[2]}c=H3DU.ShaderProgram._fromShaderInfo(b,a);this._customPrograms.push([a,
b,c]);return c};p.ProgramCache.prototype.getProgram=function(a,b){if(!b)throw Error();if(!H3DU.is3DContext(b))return null;var c=this._programs[a];if(c)for(var d=0;d<c.length;d++){if(c[d][0]===b)return c[d][1]}else this._programs[a]=[];c="";0!==(a&H3DU.Scene3D.LIGHTING_ENABLED)&&(c+="#define SHADING\n");0!==(a&H3DU.Scene3D.SPECULAR_ENABLED)&&(c+="#define SPECULAR\n");0!==(a&H3DU.Scene3D.PHYSICAL_BASED_ENABLED)&&(c+="#define PHYSICAL_BASED\n");0!==(a&H3DU.Scene3D.METALNESS_ENABLED)&&(c+="#define METALNESS\n");
0!==(a&H3DU.Scene3D.METALNESS_MAP_ENABLED)&&(c+="#define METALNESS_MAP\n");0!==(a&H3DU.Scene3D.ROUGHNESS_ENABLED)&&(c+="#define ROUGHNESS\n");0!==(a&H3DU.Scene3D.ROUGHNESS_MAP_ENABLED)&&(c+="#define ROUGHNESS_MAP\n");0!==(a&H3DU.Scene3D.NORMAL_MAP_ENABLED)&&(c+="#define NORMAL_MAP\n");0!==(a&H3DU.Scene3D.TEXTURE_ENABLED)&&(c+="#define TEXTURE\n");0!==(a&H3DU.Scene3D.COLORATTR_ENABLED)&&(c+="#define COLORATTR\n");0!==(a&H3DU.Scene3D.INVERT_ROUGHNESS_ENABLED)&&(c+="#define INVERT_ROUGHNESS\n");0!==
(a&H3DU.Scene3D.ENV_MAP_ENABLED)&&(c+="#define ENV_MAP\n");0!==(a&H3DU.Scene3D.ENV_EQUIRECT_ENABLED)&&(c+="#define ENV_EQUIRECT\n");0!==(a&H3DU.Scene3D.EMISSION_MAP_ENABLED)&&(c+="#define EMISSION_MAP\n");0!==(a&H3DU.Scene3D.OCCLUSION_MAP_ENABLED)&&(c+="#define OCCLUSION_MAP\n");0!==(a&H3DU.Scene3D.SPECULAR_MAP_ENABLED)&&(c+="#define SPECULAR_MAP\n#define SPECULAR\n");c=new H3DU.ShaderProgram(b,c+H3DU.ShaderProgram.getDefaultVertex(),c+H3DU.ShaderProgram.getDefaultFragment());this._programs[a].push([b,
c]);return c};p.prototype.getContext=function(){return this.context};p.NONE=0;p.BACK=1;p.FRONT=2;p.FRONT_AND_BACK=3;p.CCW=0;p.CW=1;p.prototype.cullFace=function(a){this._cullFace=a===H3DU.Scene3D.BACK||a===H3DU.Scene3D.FRONT||a===H3DU.Scene3D.FRONT_AND_BACK?a:0;return this};p.prototype._setFace=function(){if(this._is3d)return this._cullFace===H3DU.Scene3D.BACK?(this.context.enable(this.context.CULL_FACE),this.context.cullFace(this.context.BACK)):this._cullFace===H3DU.Scene3D.FRONT?(this.context.enable(this.context.CULL_FACE),
this.context.cullFace(this.context.FRONT)):this._cullFace===H3DU.Scene3D.FRONT_AND_BACK?(this.context.enable(this.context.CULL_FACE),this.context.cullFace(this.context.FRONT_AND_BACK)):this.context.disable(this.context.CULL_FACE),this._frontFace===H3DU.Scene3D.CW?this.context.frontFace(this.context.CW):this.context.frontFace(this.context.CCW),this};p.prototype.frontFace=function(a){this._frontFace=a===H3DU.Scene3D.CW?a:0;return this};p.prototype.setAutoResize=function(a){this.autoResize=!!a;return this};
p.prototype.getAutoResize=function(){return!!this.autoResize};p.prototype.setUseDevicePixelRatio=function(a){var b=!!this.useDevicePixelRatio;this._pixelRatio=(this.useDevicePixelRatio=!!a)&&window.devicePixelRatio?window.devicePixelRatio:1;b!==this.useDevicePixelRatio&&this.setDimensions(this.width,this.height);return this};p.prototype.getClearColor=function(){return this.clearColor.slice(0,4)};p.prototype.useProgram=function(a){"undefined"!==typeof a&&null!==a&&console.warn("Unused parameter program is defined");
console.warn("The 'useProgram' method is obsolete.  Instead of this method, use the 'setShader' program of individual shapes to set the shader programs they use.");return this};p.prototype.setDimensions=function(a,b){if(0>a||0>b)throw Error("width or height negative");this.width=Math.ceil(a);this.height=Math.ceil(b);this.context.canvas.width=this.width*this._pixelRatio;this.context.canvas.height=this.height*this._pixelRatio;this._is3d&&this.context.viewport(0,0,this.width*this._pixelRatio,this.height*
this._pixelRatio);"undefined"!==typeof this.fbo&&this.fbo&&(this.fbo.dispose(),this.fbo=this.createBuffer());return this};p.prototype.getWidth=function(){return this.width};p.prototype.getHeight=function(){return this.height};p.prototype.getAspect=function(){var a=this.getHeight();return 0>=a?1:this.getWidth()/a};p.prototype.getClientWidth=function(){return this.context.canvas.clientWidth};p.prototype.getClientHeight=function(){return this.context.canvas.clientHeight};p.prototype.getClientAspect=
function(){var a=this.getClientHeight();return 0>=a?1:this.getClientWidth()/a};p.prototype.createBuffer=function(){return new H3DU.FrameBuffer(this.context,this.getWidth(),this.getHeight())};p.prototype.getProjectionMatrix=function(){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");return this._subScene._projectionMatrix.slice(0,16)};p.prototype.getViewMatrix=function(){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");
return this._subScene._viewMatrix.slice(0,16)};p.prototype.setPerspective=function(a,b,c,d){return this.setProjectionMatrix(H3DU.Math.mat4perspective(a,b,c,d))};p.prototype.setOrthoAspect=function(a,b,c,d,e,f,g){if("undefined"===typeof g||null===g)g=this.getClientAspect();0===g&&(g=1);return this.setProjectionMatrix(H3DU.Math.mat4orthoAspect(a,b,c,d,e,f,g))};p.prototype.setOrtho2DAspect=function(a,b,c,d,e){return this.setOrthoAspect(a,b,c,d,-1,1,e)};p.prototype.setFrustum=function(a,b,c,d,e,f){return this.setProjectionMatrix(H3DU.Math.mat4frustum(a,
b,d,c,e,f))};p.prototype.setOrtho=function(a,b,c,d,e,f){return this.setProjectionMatrix(H3DU.Math.mat4ortho(a,b,c,d,e,f))};p.prototype.setOrtho2D=function(a,b,c,d){return this.setProjectionMatrix(H3DU.Math.mat4ortho(a,b,c,d,-1,1))};p.prototype._setClearColor=function(){this._is3d&&this.context.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]);return this};p.prototype.dispose=function(){this.context=null;this._programs&&this._programs.dispose();this._textureLoader&&
this._textureLoader.dispose();this._meshLoader&&this._meshLoader.dispose();this._meshLoader=this._textureLoader=this._programs=null};p.prototype.setClearColor=function(a,b,c,d){this.clearColor=H3DU.toGLColor(a,b,c,d);return this._setClearColor()};p.prototype.loadTexture=function(a){return this._textureLoader.loadTexture(a)};p.prototype.loadAndMapTexture=function(a){return a.constructor===H3DU.Texture?this._textureLoader.loadAndMapTexture(a.name,this.context):"string"===typeof a?this._textureLoader.loadAndMapTexture(a,
this.context):null};p.prototype.loadAndMapTextures=function(a,b,c){for(var d=[],e=0;e<a.length;e++)d.push(this.loadAndMapTexture(a[e]));return H3DU.getPromiseResults(d,b,c)};p.prototype.clear=function(){this._is3d&&this.context.clear(this.context.COLOR_BUFFER_BIT|this.context.DEPTH_BUFFER_BIT|this.context.STENCIL_BUFFER_BIT);return this};p.prototype.clearDepth=function(){this._is3d&&this.context.clear(this.context.DEPTH_BUFFER_BIT);return this};p.prototype.vertexCount=function(){if(this._errors)throw Error();
if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");return this._subScene.vertexCount()};p.prototype.primitiveCount=function(){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");return this._subScene.primitiveCount()};p.prototype.setProjectionMatrix=function(a){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");
this._subScene.setProjectionMatrix(a);return this};p.prototype.setViewMatrix=function(a){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");this._subScene.setViewMatrix(a);return this};p.prototype.setLookAt=function(a,b,c){return this.setViewMatrix(H3DU.Math.mat4lookat(a,b,c))};p.prototype.addShape=function(a){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");
this._subScene.addShape(a);this.shapes.push(a);return this};p.prototype.makeShape=function(a){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");return new H3DU.Shape(a)};p.prototype.removeShape=function(a){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");this._subScene.removeShape(a);for(var b=0;b<this.shapes.length;b++)this.shapes[b]===
a&&(this.shapes.splice(b,1),b--);return this};p.prototype.getLights=function(){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");return this._subScene.getLights()};p.prototype.setDirectionalLight=function(a,b,c,d){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");this.getLights().setDirectionalLight(a,b,c,d);return this};
p.prototype.setLightParams=function(a,b){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");this.getLights().setParams(a,b);return this};p.prototype.setAmbient=function(a,b,c,d){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");this.getLights().setAmbient(a,b,c,d);return this};p.prototype.setPointLight=function(a,b,c,
d){if(this._errors)throw Error();if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");this.getLights().setPointLight(a,b,c,d);return this};p.prototype._clearForPass=function(a){var b=0;a.clearColor&&(b|=this.context.COLOR_BUFFER_BIT);a.clearDepth&&(b|=this.context.DEPTH_BUFFER_BIT);a.clearStencil&&(b|=this.context.STENCIL_BUFFER_BIT);this._is3d&&0!==b&&this.context.clear(b)};p.prototype.render=function(a){if(a instanceof H3DU.Batch3D)return this.render([new H3DU.RenderPass(a)]);
if(this.autoResize){var b=this.context.canvas;b.height===Math.ceil(b.clientHeight)*this._pixelRatio&&b.width===Math.ceil(b.clientWidth)*this._pixelRatio||this.setDimensions(b.clientWidth,b.clientHeight)}this._setFace();var b=this.getClientWidth(),c=this.getClientHeight();if("undefined"===typeof a||null===a){this._is3d&&this.context.clear(this.context.COLOR_BUFFER_BIT|this.context.DEPTH_BUFFER_BIT);a=this._subScene.shapes;var d=[],d=d.concat(this.shapes);this._subScene.shapes=d;this._subScene.resize(b,
c);this._subScene.render(this);this._subScene.shapes=a}else{this._renderedOutsideScene=!0;for(var d=this.getWidth(),e=this.getHeight(),f=0;f<a.length;f++){var g=a[f],h=!1,m=b,n=c;g.frameBuffer&&(g.useFrameBufferSize&&(h=!0,m=g.frameBuffer.getWidth(),n=g.frameBuffer.getHeight(),this.setDimensions(m,n)),this._textureLoader.bindFrameBuffer(g.frameBuffer,this.context,0));this._clearForPass(g);a[f].batch.resize(m,n);a[f].batch.render(this,g);g.frameBuffer&&(h&&this.setDimensions(d,e),this._textureLoader.unbindFrameBuffer(g.frameBuffer,
this.context))}}return this};p.prototype.useFilter=function(a){if(this._renderedOutsideScene)throw Error("A non-default scene has been rendered, so this method is disabled.");console.warn("The useFilter method is deprecated. Use the H3DU.Batch3D.forFilter method to create a batch for rendering filter effects from a frame buffer.");a instanceof H3DU.ShaderProgram?this._subScene._useShader(a.shaderInfo):this._subScene._useShader(a);return this};var ra=function(a){if(Math.floor(a)!==a||0>=a)return!1;
for(;1<a&&0===(a&1);)a>>=1;return 1===a},ha=function(a){this.mshade=a};ha._textureSizeZeroZero=[0,0];ha.prototype.bind=function(a,b,c){if(!this.mshade)return this;var d=this.mshade,e="undefined"!==typeof d.albedo&&null!==d.albedo?d.albedo:d.diffuse,e={textureSize:ha._textureSizeZeroZero,md:4===e.length?e:[e[0],e[1],e[2],4>e.length?1:e[3]]};d.basic||("undefined"!==typeof d.shininess&&null!==d.shininess&&(e.mshin=d.shininess),"undefined"!==typeof d.metalness&&null!==d.metalness&&(e.metalness=d.metalness),
"undefined"!==typeof d.roughness&&null!==d.roughness&&(e.roughness=d.roughness),"undefined"!==typeof d.ambient&&null!==d.ambient&&(e.ma=3===d.ambient.length?d.ambient:[d.ambient[0],d.ambient[1],d.ambient[2]]),e.ms=3===d.specular.length?d.specular:[d.specular[0],d.specular[1],d.specular[2]],e.me=3===d.emission.length?d.emission:[d.emission[0],d.emission[1],d.emission[2]]);a.setUniforms(e);var e=0,f=[];f.push(["undefined"===typeof d.albedoMap?null:d.albedoMap,"texture","textureSize"]);f.push(["undefined"===
typeof d.texture?null:d.texture,"texture","textureSize"]);f.push(["undefined"===typeof d.specularMap?null:d.specularMap,"specularMap"]);f.push(["undefined"===typeof d.normalMap?null:d.normalMap,"normalMap"]);f.push(["undefined"===typeof d.metalnessMap?null:d.metalnessMap,"metalnessMap"]);f.push(["undefined"===typeof d.occlusionMap?null:d.occlusionMap,"occlusionMap"]);f.push(["undefined"===typeof d.roughnessMap?null:d.roughnessMap,"roughnessMap"]);f.push(["undefined"===typeof d.environmentMap?null:
d.environmentMap,"envMap"]);f.push(["undefined"===typeof d.emissionMap?null:d.emissionMap,"emissionMap"]);for(var g=0;g<f.length;g++)if("undefined"!==typeof f[g][0]&&null!==f[g][0]){var h="undefined"===typeof f[g][2]?null:f[g][2],m=f[g][0],n=m instanceof H3DU.Texture?m._toInfo():m;ha.bindTexture(m,n,b,a,e++,c,f[g][1],h)}if("undefined"!==typeof d.shader&&null!==d.shader)for(var l in d.shader.uniformValues||{})Object.prototype.hasOwnProperty.call(d.shader.uniformValues,l)&&(f=d.shader.uniformValues[l],
"undefined"!==typeof f&&null!==f&&f instanceof H3DU.TextureInfo&&ha.bindTexture(f,f,b,a,e++,c,l,null));return this};Z.textureFilters=function(a,b,c,d){a.texParameteri(d,a.TEXTURE_MAG_FILTER,c.magFilter);if("undefined"!==typeof WebGL2RenderingContext&&null!==WebGL2RenderingContext&&a instanceof WebGL2RenderingContext||ra(b.getWidth())&&ra(b.getHeight()))a.generateMipmap(d);else{b=c.minFilter;if(b===a.NEAREST_MIPMAP_NEAREST||b===a.NEAREST_MIPMAP_LINEAR)b=a.NEAREST;if(b===a.LINEAR_MIPMAP_NEAREST||b===
a.LINEAR_MIPMAP_LINEAR)b=a.LINEAR;a.texParameteri(d,a.TEXTURE_MIN_FILTER,b);a.texParameteri(d,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE);a.texParameteri(d,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE)}};Z.prototype._init=function(a,b,c){if(!a.image)throw Error();this.context=c=c&&c.getContext?c.getContext():c;this.loadedTexture=c.createTexture();c.activeTexture(c.TEXTURE0);c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL,b.topDown?0:1);var d=b.target;c.bindTexture(d,this.loadedTexture);"src"in a.image?c.texImage2D(d,0,b.internalFormat,
b.format,c.UNSIGNED_BYTE,a.image):c.texImage2D(d,0,b.internalFormat,a.getWidth(),a.getHeight(),0,b.format,c.UNSIGNED_BYTE,a.image);Z.textureFilters(c,a,b,d)};Z.prototype.dispose=function(){this.loadedTexture&&this.context&&this.context.deleteTexture(this.loadedTexture);this.loadedTexture=this.context=null};va.prototype.dispose=function(){this.loadedTexture&&this.context&&this.context.deleteTexture(this.loadedTexture);this.loadedTexture=this.context=null};ha.bindTexture=function(a,b,c,d,e,f,g,h){if("undefined"===
typeof b||null===b)throw Error();if("undefined"===typeof a||null===a)c&&(c.activeTexture(c.TEXTURE0+e),c.bindTexture(c.TEXTURE_2D,null),c.bindTexture(c.TEXTURE_CUBE_MAP,null));else{var m=a instanceof H3DU.FrameBufferInfo;if(!(m||a instanceof H3DU.Texture||a instanceof H3DU.CubeMap||a instanceof H3DU.TextureInfo))throw Error("unsupported texture type");var n=null;if(m)a=f.mapFrameBuffer(a,c);else{if(a instanceof H3DU.TextureInfo){var l=f.getTexture(a.uri);if("undefined"===typeof l||null===l){var k=
this,q=d;f.loadAndMapTexture(a,c).then(function(){k.bind(q,c,f)})}else a=l}if(0===a.loadStatus){k=this;q=d;a.loadImage().then(function(){k.bind(q,c,f)});return}2<=a.loadStatus&&(n=f._mapTextureWithInfo(a,b,c))}if("undefined"!==typeof n&&null!==n||m)if(l={},l[g]=e,"undefined"!==typeof h&&null!==h&&(l[h]=[a.getWidth(),a.getHeight()]),d.setUniforms(l),c.activeTexture(c.TEXTURE0+e),m)c.bindTexture(c.TEXTURE_2D,a.colorTexture),a.colorTexture&&(c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,b.magFilter),
c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,b.minFilter),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,b.wrapS),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,b.wrapT));else if(d=a instanceof H3DU.CubeMap?c.TEXTURE_CUBE_MAP:b.target,c.bindTexture(d,n.loadedTexture),f._setMaxAnisotropy(c,d),c.texParameteri(d,c.TEXTURE_MAG_FILTER,b.magFilter),"undefined"!==typeof WebGL2RenderingContext&&null!==WebGL2RenderingContext&&c instanceof WebGL2RenderingContext||ra(a.getWidth())&&ra(a.getHeight()))c.texParameteri(d,
c.TEXTURE_MIN_FILTER,b.minFilter),c.texParameteri(d,c.TEXTURE_WRAP_S,b.wrapS),c.texParameteri(d,c.TEXTURE_WRAP_T,b.wrapT);else{a=b.minFilter;if(a===c.NEAREST_MIPMAP_NEAREST||a===c.NEAREST_MIPMAP_LINEAR)a=c.NEAREST;if(a===c.LINEAR_MIPMAP_NEAREST||a===c.LINEAR_MIPMAP_LINEAR)a=c.LINEAR;c.texParameteri(d,c.TEXTURE_MIN_FILTER,a);c.texParameteri(d,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(d,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE)}}};aa.emptyW1=[0,0,0,1];aa.emptyW0=[0,0,0,0];aa.emptyAtten=[1,0,0,0];aa.prototype.bind=
function(a,b){var c,d=this.lights;if(!d||!a)return this;var e={};e.sceneAmbient=3===d.sceneAmbient.length?d.sceneAmbient:d.sceneAmbient.slice(0,3);for(var f=0;f<d.lights.length;f++){var g=d.lights[f];c="lights["+f+"]";e[c+".diffuse"]=4===g.diffuse.length?g.diffuse:[g.diffuse[0],g.diffuse[1],g.diffuse[2],1];e[c+".specular"]=4===g.specular.length?g.specular:[g.specular[0],g.specular[1],g.specular[2],1];var h=H3DU.Math.mat4transform(b,d.lights[f].position);e[c+".position"]=h;e[c+".radius"]=[Math.max(0,
g.radius*g.radius*g.radius*g.radius),0,0,0]}for(f=d.lights.length;f<H3DU.Lights.MAX_LIGHTS;f++)c="lights["+f+"]",e[c+".diffuse"]=aa.emptyW1,e[c+".specular"]=aa.emptyW1,e[c+".position"]=aa.emptyW0,e[c+".radius"]=aa.emptyW0;a.setUniforms(e);return this};y._PerspectiveView=function(a,b,c,d){this.fov=b;this.near=c;this.far=d;this.batch=a;this.lastAspect=null;this.update=function(a,b){var c=1*a/b;c===this.lastAspect||isNaN(c)||(this.lastAspect=c,this.batch.setProjectionMatrix(H3DU.Math.mat4perspective(this.fov,
c,this.near,this.far)))};this.update(1,1)};y._OrthoView=function(a,b,c,d,e,f,g){this.a=b;this.b=c;this.c=d;this.d=e;this.e=f;this.f=g;this.batch=a;this.lastAspect=null;this.update=function(a,b){var c=1*a/b;c===this.lastAspect||isNaN(c)||(this.lastAspect=c,this.batch.setProjectionMatrix(H3DU.Math.mat4orthoAspect(this.a,this.b,this.c,this.d,this.e,this.f,c)))};this.update(1,1)};y._isIdentityExceptTranslate=function(a){return 1===a[0]&&0===a[1]&&0===a[2]&&0===a[3]&&0===a[4]&&1===a[5]&&0===a[6]&&0===
a[7]&&0===a[8]&&0===a[9]&&1===a[10]&&0===a[11]&&1===a[15]};y._setupMatrices=function(a,b,c,d){var e={},f=null,g;for(g in a.uniformSemantics)if(Object.prototype.hasOwnProperty.call(a.uniformSemantics,g)){var h=a.uniformSemantics[g];switch(h){case H3DU.Semantic.MODEL:e[g]=d;break;case H3DU.Semantic.VIEW:e[g]=c;break;case H3DU.Semantic.PROJECTION:e[g]=b;break;case H3DU.Semantic.MODELVIEW:case H3DU.Semantic.MODELVIEWPROJECTION:case H3DU.Semantic.MODELVIEWINVERSETRANSPOSE:f||(H3DU.Batch3D._isIdentityExceptTranslate(c)?
(f=d.slice(0,16),f[12]+=c[12],f[13]+=c[13],f[14]+=c[14]):f=H3DU.Math.mat4multiply(c,d));h===H3DU.Semantic.MODELVIEW?e[g]=f:h===H3DU.Semantic.MODELVIEWPROJECTION?e[g]=H3DU.Math.mat4multiply(b,f):h===H3DU.Semantic.MODELVIEWINVERSETRANSPOSE&&(e[g]=H3DU.Math.mat4inverseTranspose3(f));break;case H3DU.Semantic.VIEWINVERSE:e[g]=H3DU.Math.mat4invert(c)}}a.setUniforms(e)};y._isSameMatrix=function(a,b){return a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&a[6]===b[6]&&a[7]===
b[7]&&a[8]===b[8]&&a[9]===b[9]&&a[10]===b[10]&&a[11]===b[11]&&a[12]===b[12]&&a[13]===b[13]&&a[14]===b[14]&&a[15]===b[15]};y.prototype.setProjectionMatrix=function(a){H3DU.Batch3D._isSameMatrix(this._projectionMatrix,a)||(this._projectionMatrix=a.slice(0,16),this._frustum=null);return this};y.prototype.perspectiveAspect=function(a,b,c){this._projectionUpdater=new H3DU.Batch3D._PerspectiveView(this,a,b,c);return this};y.prototype.setLookAt=function(a,b,c){return this.setViewMatrix(H3DU.Math.mat4lookat(a,
b,c))};y.prototype.orthoAspect=function(a,b,c,d,e,f){this._projectionUpdater=new H3DU.Batch3D._OrthoView(this,a,b,c,d,e,f);return this};y.prototype.ortho2DAspect=function(a,b,c,d){return this.orthoAspect(a,b,c,d,-1,1)};y.prototype._useShader=function(a){this._globalShader=a;return this};y.prototype.setViewMatrix=function(a){H3DU.Batch3D._isSameMatrix(this._viewMatrix,a)||(this._viewMatrix=a.slice(0,16),this._frustum=null);return this};y.prototype.getProjectionMatrix=function(){return this._projectionMatrix.slice(0,
16)};y.prototype.getProjectionViewMatrix=function(){return H3DU.Math.mat4multiply(this.getProjectionMatrix(),this.getViewMatrix())};y.prototype.getViewMatrix=function(){return this._viewMatrix.slice(0,16)};y.prototype._getFrustum=function(){if("undefined"===typeof this._frustum||null===this._frustum){var a=H3DU.Math.mat4multiply(this._projectionMatrix,this._viewMatrix);this._frustum=H3DU.Math.mat4toFrustumPlanes(a)}return this._frustum};y.prototype.getLights=function(){return this.lights};y.prototype.addShape=
function(a){if(!a)throw Error();a.parent=null;this.shapes.push(a);return this};y.prototype.shapeCount=function(){return this.shapes.length};y.prototype.getShape=function(a){return"undefined"===typeof this.shapes[a]?null:this.shapes[a]};y.prototype.setShape=function(a,b){this.shapes[a]=b;return this};y.prototype.vertexCount=function(){for(var a=0,b=0;b<this.shapes.length;b++)a+=this.shapes[b].vertexCount();return a};y.prototype.primitiveCount=function(){for(var a=0,b=0;b<this.shapes.length;b++)a+=
this.shapes[b].primitiveCount();return a};y.prototype.removeShape=function(a){for(var b=0;b<this.shapes.length;b++)this.shapes[b]===a&&(this.shapes.splice(b,1),b--);return this};y.prototype._renderShape=function(a,b){if(a.constructor===H3DU.ShapeGroup){if(a.visible)for(var c=0;c<a.shapes.length;c++)this._renderShape(a.shapes[c],b)}else if(!a.isCulled(this._getFrustum())){var c=null,d;"undefined"!==typeof b.shader&&null!==b.shader?c=b.scene._programs.getCustomProgram(b.shader,b.context):"undefined"!==
typeof this._globalShader&&null!==this._globalShader?c=b.scene._programs.getCustomProgram(this._globalShader,b.context):(a.material instanceof H3DU.Material||a.material instanceof H3DU.PbrMaterial)&&null!==a.material.shader&&(c=b.scene._programs.getCustomProgram(a.material.shader,b.context));d=H3DU.Scene3D._flagsForShape(a);if("undefined"===typeof c||null===c)c=b.scene._programs.getProgram(d,b.context);"undefined"!==typeof c&&null!==c&&(b.prog!==c&&(c.use(),(new aa(this.lights)).bind(c,this._viewMatrix),
b.prog=c),H3DU.Batch3D._setupMatrices(c,this._projectionMatrix,this._viewMatrix,a.getMatrix()),H3DU.Batch3D._getMaterialBinder(a.material).bind(c,b.context,b.scene._textureLoader),b.scene._meshLoader.draw(a.meshBuffer,c))}};y.prototype.resize=function(a,b){this._projectionUpdater&&this._projectionUpdater.update(a,b)};y.prototype.render=function(a,b){var c={};c.scene=a;c.context=a.getContext();c.shader=b?b.shader:null;for(var d=0;d<this.shapes.length;d++)this._renderShape(this.shapes[d],c);return this};
y.forFilter=function(a,b,c){if("undefined"===typeof c||null===c)c=H3DU.ShaderProgram.makeCopyEffect(a);a=new H3DU.Batch3D;var d=(new H3DU.MeshBuffer).setAttribute("POSITION",[-1,1,0,-1,-1,0,1,1,0,1,-1,0],3).setAttribute("TEXCOORD",[0,1,0,0,1,1,1,0],2).setIndices([0,1,2,2,1,3]),d=new H3DU.Shape(d);d.setTexture(b);d.setShader(c);a.addShape(d);return a};y._getMaterialBinder=function(a){return a&&a instanceof H3DU.Material||a&&a instanceof H3DU.PbrMaterial?new ha(a):{}};var P={vecZeros:function(a){for(var b=
[],c=0;c<a;c++)b[c]=0;return b},vecSub:function(a,b){for(var c=[],d=0;d<a.length;d++)c[d]=a[d]-b[d];return c},vecSubInPlace:function(a,b){for(var c=0;c<a.length;c++)a[c]-=b[c];return a},vecScale:function(a,b){for(var c=[],d=0;d<a.length;d++)c[d]=a[d]*b;return c},vecSubScaleInPlace:function(a,b,c){for(var d=0;d<a.length;d++)a[d]=(a[d]-b[d])*c;return a},vecNormalizeInPlace:function(a){for(var b=0,c=0;c<a.length;c++)b+=a[c]*a[c];b=Math.sqrt(b);if(0!==b)for(b=1/b,c=0;c<a.length;c++)a[c]*=b;return a},
vecLength:function(a){for(var b=0,c=0;c<a.length;c++)b+=a[c]*a[c];return Math.sqrt(b)}};w.prototype.endPoints=function(){return"undefined"!==typeof this.curveParam&&null!==this.curveParam?this.curveParam.endPoints():"undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.endPoints&&null!==this.curve.endPoints?this.curve.endPoints():[0,1]};w.prototype._getCoord=function(a){return"undefined"!==typeof this.curveParam&&null!==this.curveParam?this.curveParam.getCoordinate(a):
a};w._EPSILON=1E-5;w.prototype.evaluate=function(a){return"undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.evaluate&&null!==this.curve.evaluate?this.curve.evaluate(this._getCoord(a)):[0,0,0]};w.prototype.velocity=function(a){if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.velocity&&null!==this.curve.velocity)return this.curve.velocity(this._getCoord(a));var b=w._EPSILON,c=this.evaluate(a+
b);0===c[0]&&0===c[1]&&0===c[2]&&(b=-b,c=this.evaluate(a+b));return P.vecSubScaleInPlace(c,this.evaluate(a),1/b)};w.prototype.accel=function(a){if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.accel&&null!==this.curve.accel)return this.curve.accel(this._getCoord(a));var b=w._EPSILON,c=this.velocity(a+b);0===c[0]&&0===c[1]&&0===c[2]&&(b=-b,c=this.velocity(a+b));return P.vecSubScaleInPlace(c,this.velocity(a),1/b)};w.prototype.jerk=function(a){if("undefined"!==
typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.jerk&&null!==this.curve.jerk)return this.curve.jerk(this._getCoord(a));var b=w._EPSILON,c=this.accel(a+b);0===c[0]&&0===c[1]&&0===c[2]&&(b=-b,c=this.accel(a+b));return P.vecSubScaleInPlace(c,this.accel(a),1/b)};w.prototype.normal=function(a){if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.normal&&null!==this.curve.normal)return this.curve.normal(this._getCoord(a));
var b=w._EPSILON,c=this.tangent(a+b);0===c[0]&&0===c[1]&&0===c[2]&&(c=this.tangent(a+-b));c=P.vecSubInPlace(c,this.tangent(a));return P.vecNormalizeInPlace(c)};w.prototype.tangent=function(a){return P.vecNormalizeInPlace(this.velocity(a))};w.prototype.getLength=function(){var a=this.endPoints();return this.arcLength(a[1])};var ma=[.9969339225295955,.00825771143316837,0,.9815606342467192,.02303608403898155,.04717533638651112,.9505377959431213,.03891523046929952,0,.9041172563704749,.05369701760775668,
.10693932599531891,.8435581241611533,.06725090705083998,0,.7699026741943047,.07992027533360173,.16007832854334625,.6840598954700559,.09154946829504924,0,.5873179542866175,.10164973227906016,.20316742672306579,.4813394504781571,.11002260497764407,0,.3678314989981802,.11671205350175679,.23349253653835478,.24850574832046932,.12162630352394839,0,.1252334085114689,.12458416453615606,.24914704581340283,0,.12555689390547423,0];w.prototype.arcLength=function(a){if("undefined"!==typeof this.curveParam&&null!==
this.curveParam&&this.curveParam instanceof w._ArcLengthParam)return a;if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.arcLength&&null!==this.curve.arcLength)return this.curve.arcLength(this._getCoord(a));var b=this.endPoints();if(a===b[0])return 0;var c=this;return ta(function(a){return P.vecLength(c.velocity(a))},Math.min(a,b[0]),Math.max(a,b[0]),a>=b[0]?1:-1,0)};w.prototype.getPoints=function(a){if(0===a)return[];if(0>a)throw Error();for(var b=
this.endPoints(),c=[this.evaluate(b[0])],d=1;d<a;d++)c.push(this.evaluate(b[0]+d/(a-1)*(b[1]-b[0])));return c};w._ChangeEnds=function(a,b){this.u1=a;this.u2=b;this.getCoordinate=function(a){return a};this.endPoints=function(){return[this.u1,this.u2]}};w._FitRange=function(a,b,c){this.newEp1=b;this.newEp2=c;this.invNewEpDelta=1/(c-b);a=a.endPoints();this.origEp1=a[0];this.origEp2=a[1];this.getCoordinate=function(a){return this.origEp1+(this.origEp2-this.origEp1)*(a-this.newEp1)*this.invNewEpDelta};
this.endPoints=function(){return[b,c]}};w._ArcLengthParam=function(a){this.curve=a;this.ep=this.curve.endPoints();this.segments=[];a=this.ep[0];for(var b=0,c=this.curve.getLength(),c=Math.min(Math.max(10,Math.ceil(18*c)),50),d=1;d<=c;d++){var e=this.ep[0]+d/c*(this.ep[1]-this.ep[0]),f=this.curve.arcLength(e);this.segments.push([b,f,a,e]);a=e;b=f}this.length=0===this.segments.length?0:this.segments[this.segments.length-1][1];this._vecLength=function(a){for(var b=0,c=0;c<a.length;c++)b+=a[c]*a[c];return Math.sqrt(b)};
this._solveArcLength=function(a,b,c,d){for(var e=0;10>e;e++){var f=this.curve.arcLength(b)-a;if(1E-10>Math.abs(f)&&b>=c&&b<d)break;var g=this._vecLength(this.curve.velocity(b));if(0===g)break;var g=f/g,h=b-g;if(0===g)break;c!==Number.NEGATIVE_INFINITY&&d!==Number.POSITIVE_INFINITY?0>f?(c=Math.max(c,b),b=h,h>=d&&(b=c+.5*(d-c))):0<f&&(d=Math.min(d,b),b=h,h<=c&&(b=c+.5*(d-c))):b=h}return b}};w._ArcLengthParam.prototype.getCoordinate=function(a){var b,c;if(a>this.length)return b=this.curve.endPoints(),
c=b[0]+a/this.length*(b[1]-b[0]),this._solveArcLength(a,c,b[0],Number.POSITIVE_INFINITY);if(0>a)return b=this.curve.endPoints(),c=b[0]+a/this.length*(b[1]-b[0]),this._solveArcLength(a,c,Number.NEGATIVE_INFINITY,0);if(a===this.length)return b=this.curve.endPoints(),b[1];if(0===a)return b=this.curve.endPoints(),b[0];c=0;for(var d=this.segments.length,e=0;c<d;){e+=1;if(20<e)throw Error();var f=c+((d-c)/2|0);b=this.segments[f];if(a===b[0])return b[2];if(a===b[1])return b[3];if(a>b[0]&&a<b[1])return c=
b[2]+(a-b[0])/(b[1]-b[0])*(b[3]-b[2]),1E-10<=b[1]-b[0]?this._solveArcLength(a,c,b[2],b[3]):c;a<b[0]?d=f:c=f+1}throw Error("Internal error");};w._ArcLengthParam.prototype.endPoints=function(){return[0,this.length]};w.prototype.changeEnds=function(a,b){return new w(this,new w._ChangeEnds(a,b))};w.prototype.fitRange=function(a,b){return new w(this,new w._FitRange(this,a,b))};w.prototype.toArcLengthParam=function(){return new w(this,new w._ArcLengthParam(this))};var Q=function(a){this.surface="undefined"===
typeof a?null:a};Q._EPSILON=1E-5;Q.prototype.tangent=function(a,b){if("undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.tangent&&null!==this.surface.tangent)return this.surface.tangent(a,b);var c=Q._EPSILON,d=this.evaluate(a+c,b);0===d[0]&&0===d[1]&&0===d[2]&&(c=-c,d=this.evaluate(a+c,b));return P.vecSubScaleInPlace(d,this.evaluate(a,b),1/c)};Q.prototype.bitangent=function(a,b){if("undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.bitangent&&
null!==this.surface.bitangent)return this.surface.bitangent(a,b);var c=Q._EPSILON,d=this.evaluate(a,b+c);0===d[0]&&0===d[1]&&0===d[2]&&(c=-c,d=this.evaluate(a,b+c));return P.vecSubScaleInPlace(d,this.evaluate(a,b),1/c)};Q.prototype.normal=function(a,b){return P.vecNormalizeInPlace(this.gradient(a,b))};Q.prototype.gradient=function(a,b){if("undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.gradient&&null!==this.surface.gradient)return this.surface.gradient(a,
b);var c=this.tangent(a,b),d=this.bitangent(a,b);if(0===P.vecLength(d))return c;if(0!==P.vecLength(c)){if(3!==c.length||3!==d.length){var e=c.length,f=P.vecZeros(e),c=[c[0]||0,c[1]||0,c[2]||0],d=[d[0]||0,d[1]||0,d[2]||0],c=H3DU.Math.vec3cross(c,d);f[0]=c[0];f[1]=c[1];f[2]=c[2];return f.slice(0,e)}return H3DU.Math.vec3cross(c,d)}return d};Q.prototype.evaluate=function(a,b){return"undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.evaluate&&null!==this.surface.evaluate?
this.surface.evaluate(a,b):[0,0,0]};Q.prototype.endPoints=function(){return"undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.endPoints&&null!==this.surface.endPoints?this.surface.endPoints():[0,1,0,1]};var M=function(a,b,c,d){if("undefined"===typeof d||null===d)d=b;if("undefined"===typeof c||null===c)c=0;if(0>c||0>=b||0>=d)throw Error();this.buffer=a;this.offset=c;this.countPerValue=b;this.stride=d};M.prototype.count=function(){var a=this.buffer.length-this.offset;
return Math.floor(a/this.stride)+(a%this.stride>=this.countPerValue?1:0)};M.prototype.get=function(a){return this.buffer[this.offset+a*this.stride]};M.prototype.set=function(a,b){this.buffer[this.offset+a*this.stride]=b;return this};M.prototype.getVec=function(a,b){for(var c=this.offset+a*this.stride,d=this.buffer,e=0;e<this.countPerValue;e++)b[e]=d[c+e];return b};M.prototype.setVec=function(a,b){for(var c=this.offset+a*this.stride,d=this.buffer,e=Math.min(b.length,this.countPerValue),f=0;f<e;f++)d[c+
f]=b[f];return this};M.prototype.copy=function(){for(var a=this.count(),b=M.makeBlank(a,this.countPerValue),c=[],d=0;d<a;d++)this.getVec(d,c),b.setVec(d,c);return b};M.makeBlank=function(a,b){return new M(new Float32Array(new ArrayBuffer(a*b*4)),b)};M.makeIndices=function(a){var b;b=65536>a?new Uint16Array(new ArrayBuffer(2*a)):new Uint32Array(new ArrayBuffer(4*a));for(var c=0;c<a;c++)b[c]=c;return b};M.merge=function(a,b,c,d){var e;e=Math.max("undefined"===typeof a||null===a?0:a.countPerValue,"undefined"===
typeof c||null===c?0:c.countPerValue);var f=M.makeBlank(b.length+d.length,e),g=P.vecZeros(e);if("undefined"!==typeof a&&null!==a)for(e=0;e<b.length;e++)a&&a.getVec(b[e],g),f.setVec(e,g);if("undefined"!==typeof c&&null!==c)for(e=0;e<d.length;e++)c&&c.getVec(d[e],g),f.setVec(b.length+e,g);return f};var u=function(){this.format=H3DU.Mesh.TRIANGLES;this.attributes=[];this._bounds=null;this.indices=new Uint8Array([])};u.prototype.getIndices=function(){return this.indices};u.prototype.setIndices=function(a){if(a instanceof
Array){for(var b=0,c=a.length-1;0<=c&&!(b=Math.max(b,a[c]),65536<=b);c--);this.indices=65536<=b?new Uint32Array(a):new Uint16Array(a)}else this.indices=a.slice(0,a.length);return this};u.prototype.setPrimitiveType=function(a){this.format=a;return this};u.prototype.setAttribute=function(a,b,c,d,e){return this.setAttributeEx(a,0,b,c,d,e)};u.prototype.setAttributeEx=function(a,b,c,d,e,f){var g;if(c instanceof M){if(c.buffer instanceof M)throw Error();return this.setAttributeEx(a,b,c.buffer,c.countPerValue,
c.offset,c.stride)}if("undefined"===typeof d||null===d)throw Error();g=c instanceof Array?new Float32Array(c):c;f="undefined"===typeof f||null===f?d:f;e="undefined"===typeof e||null===e?0:e;if(0>=d||0>=f||0>e)throw Error();b=u._resolveSemantic(a,b);if("undefined"===typeof b||null===b)return console.warn("Unsupported attribute semantic: "+a),this;a=b[0];b=b[1];var h=this.getAttribute(a,b);h?(h[2].buffer=c,h[2].offset=e,h[2].countPerValue=d,h[2].stride=f):this.attributes.push([a,b,new M(g,d,e,f)]);
this._bounds=null;return this};u.prototype._getAttributes=function(){return this.attributes};u.prototype.getAttribute=function(a,b){for(var c="undefined"===typeof b||null===b?0:b,d=0;d<this.attributes.length;d++)if(this.attributes[d][0]===a&&this.attributes[d][1]===c)return this.attributes[d][2];return null};u.prototype.vertexIndices=function(a,b){var c=3,d=this.primitiveType();d===H3DU.Mesh.LINES&&(c=2);d===H3DU.Mesh.POINTS&&(c=1);d=a*c;b[0]=this.indices[d];2<=c&&(b[1]=this.indices[d+1]);3<=c&&(b[2]=
this.indices[d+2]);return b};u.prototype.primitiveCount=function(){return this.format===H3DU.Mesh.LINES?Math.floor(this.indices.length/2):this.format===H3DU.Mesh.POINTS?this.indices.length:Math.floor(this.indices.length/3)};u.prototype.getPositions=function(){var a=this.getAttribute(H3DU.Semantic.POSITION,0);if(!a)return[];for(var b=[],c=[],d=this.primitiveCount(),e=0;e<d;e++){this.vertexIndices(e,c);for(var f=[],g=0;g<c.length;g++)f.push(a.getVec(c[g],[0,0,0]));b.push(f)}return b};u.prototype.normalizeNormals=
function(){for(var a=0;a<this.attributes.length;a++){var b=this.attributes[a];if(b[0]===H3DU.Semantic.NORMAL)for(var c=[],d=b[2].count(),e=0;e<d;e++)b[2].getVec(e,c),P.vecNormalizeInPlace(c),b[2].setVec(e,c)}return this};u.prototype.reverseNormals=function(){for(var a=0;a<this.attributes.length;a++){var b=this.attributes[a];if(b[0]===H3DU.Semantic.NORMAL)for(var c=[],d=b[2].count(),e=0;e<d;e++){b[2].getVec(e,c);for(var f=0;f<c.length;f++)c[f]=-c[f];b[2].setVec(e,c)}}return this};u.prototype.setColor3=
function(a){return 3===arguments.length?this.setColor([arguments[0],arguments[1],arguments[2]]):this.setColor(a)};u.prototype.setColor=function(a){a=H3DU.toGLColor(a);for(var b=!1,c=0;c<this.attributes.length;c++){var d=this.attributes[c],e=d[2].count();if(d[0]===H3DU.Semantic.COLOR)for(var b=!0,f=0;f<e;f++)d[2].setVec(f,a)}return b?this:(this._ensureAttribute(H3DU.Semantic.COLOR,0,3),this.setColor(a))};u.prototype.reverseWinding=function(){if(this.primitiveType()===H3DU.Mesh.TRIANGLES)for(var a=
0;a+2<this.indices.length;a+=3){var b=this.indices[a+1];this.indices[a+1]=this.indices[a+2];this.indices[a+2]=b}return this};u._recalcNormals=function(a,b,c,d,e){var f=e?-1:1;e={};var g=[],h,m=b.count(),n=Math.min(a.count(),m),l=[0,0,0],k=[0,0,0],q=[0,0,0],v=[0,0,0];for(h=0;h<n;h++)if(b.setVec(h,l),!d){var A=a.getVec(h,[]);e[A]?e[A].push(h):e[A]=[h]}for(h=0;h<c.length;h+=3)l=a.getVec(c[h],l),k=a.getVec(c[h+1],k),q=a.getVec(c[h+2],q),n=H3DU.Math.vec3sub(l,q),A=H3DU.Math.vec3sub(k,q),n=H3DU.Math.vec3cross(n,
A),H3DU.Math.vec3normalizeInPlace(n),H3DU.Math.vec3scaleInPlace(n,f),b.getVec(c[h],l),b.getVec(c[h+1],k),b.getVec(c[h+2],q),H3DU.Math.vec3addInPlace(l,n),H3DU.Math.vec3addInPlace(k,n),H3DU.Math.vec3addInPlace(q,n),b.setVec(c[h],l),b.setVec(c[h+1],k),b.setVec(c[h+2],q);if(!d)for(var p in e)if(Object.prototype.hasOwnProperty.call(e,p)&&(d=e[p])&&d.constructor===Array&&2<=d.length){b.getVec(d[0],v);f=[v[0],v[1],v[2]];g[0]=v[0];g[1]=v[1];g[2]=v[2];c=3;for(h=1;h<d.length;h++){l=!1;a.getVec(d[h],v);k=v[0];
q=v[1];n=v[2];for(A=0;A<c;A+=3)if(k===g[A]&&q===g[A+1]&&n===g[A+2]){l=!0;break}l||(g[c++]=k,g[c++]=q,g[c++]=n,H3DU.Math.vec3addInPlace(f,v))}for(h=0;h<d.length;h++)b.setVec(d[h],f)}for(h=0;h<m;h++)b.getVec(h,v),H3DU.Math.vec3normalize(v),b.setVec(h,v)};u._recalcTangentsInternal=function(a,b,c,d,e,f){for(var g=[0,0,0],h=[0,0,0],m=[0,0,0],n=0;n<f.length;n+=3){var g=a.getVec(f[n],g),h=a.getVec(f[n+1],h),m=a.getVec(f[n+2],m),l;l=h[0]-g[0];var k=h[1]-g[1],q=h[2]-g[2],v=m[0]-g[0],A=m[1]-g[1],p=m[2]-g[2],
g=c.getVec(f[n],g),h=c.getVec(f[n+1],h),m=c.getVec(f[n+2],m),r=h[0]-g[0],t=h[1]-g[1],u=m[0]-g[0],x=m[1]-g[1],D=r*x-t*u;0===D?l=[0,0,0,0,0,0]:(D=1/D,t=-t,u=-u,l=[(x*l+t*v)*D,(x*k+t*A)*D,(x*q+t*p)*D,(u*l+r*v)*D,(u*k+r*A)*D,(u*q+r*p)*D]);for(k=0;3>k;k++)q=l,g=b.getVec(f[n+k],g),v=g[0],A=g[1],p=g[2],r=q[0]*v+q[1]*A+q[2]*p,r=H3DU.Math.vec3normalizeInPlace([q[0]-r*v,q[1]-r*A,q[2]-r*p]),x=q[3]*v+q[4]*A+q[5]*p,D=q[3]*r[0]+q[4]*r[1]+q[5]*r[2],q=H3DU.Math.vec3normalizeInPlace([q[3]-x*v-D*r[0],q[4]-x*A-D*r[1],
q[5]-x*p-D*r[2]]),d.setVec(f[n+k],r),e.setVec(f[n+k],q)}};u.prototype._makeRedundant=function(){for(var a=[],b=0;b<this.attributes.length;b++){var c=this.attributes[b];a.push([c[0],c[1],M.merge(c[2],this.indices,null,[])])}this.attributes=a;this.setIndices(M.makeIndices(this.indices.length))};u.prototype._ensureAttribute=function(a,b,c){var d=this.getAttribute(a,b),e=0===this.attributes.length?0:this.attributes[0][2].count(),f="undefined"!==typeof d&&null!==d?d.countPerValue:0;if(d&&f>=c)return d;
var g=M.makeBlank(e,c);if(0<f)for(c=P.vecZeros(c),f=0;f<e;f++)d.getVec(f,c),g.setVec(f,c);this.attributes.push([a,b,g]);return g};u.prototype._countPerValue=function(a){a=this.getAttribute(a);return"undefined"!==typeof a&&null!==a?a.countPerValue:0};u.prototype.recalcNormals=function(a,b){if(this.primitiveType()===H3DU.Mesh.TRIANGLES){if(3>this._countPerValue(H3DU.Semantic.POSITION))return this;this._makeRedundant();var c=this.getAttribute(H3DU.Semantic.POSITION),d=this._ensureAttribute(H3DU.Semantic.NORMAL,
0,3);u._recalcNormals(c,d,this.indices,a,b)}return this};u.prototype._recalcTangents=function(){if(this.primitiveType()===H3DU.Mesh.TRIANGLES){if(3>this._countPerValue(H3DU.Semantic.POSITION)||3>this._countPerValue(H3DU.Semantic.NORMAL)||2>this._countPerValue(H3DU.Semantic.TEXCOORD))return this;this._makeRedundant();var a=this.getAttribute(H3DU.Semantic.POSITION),b=this.getAttribute(H3DU.Semantic.NORMAL),c=this.getAttribute(H3DU.Semantic.TEXCOORD),d=this._ensureAttribute(H3DU.Semantic.TANGENT,0,3),
e=this._ensureAttribute(H3DU.Semantic.BITANGENT,0,3);u._recalcTangentsInternal(a,b,c,d,e,this.indices)}return this};u.prototype.merge=function(a){var b=[],c;if(!a)throw Error();if(a instanceof H3DU.Mesh)return this.merge(a.toMeshBuffer());if(0===a.indices.length)return this;if(0===this.indices.length){for(var d=!0,e=0;e<this.attributes.length;e++)c=this.attributes[e][2],d=d&&("undefined"===typeof c||null===c||0===c.count());if(d){for(e=0;e<a.attributes.length;e++)c=a.attributes[e],b.push([c[0],c[1],
c[2].copy()]);this._bounds=null;this.format=a.format;this.attributes=b;this.setIndices(a.indices.slice(0,a.indices.length));return this}}if(this.format!==a.format)throw Error();for(e=0;e<this.attributes.length;e++){var f=null;c=this.attributes[e];for(var d=c[0],g=c[1],h=0;h<a.attributes.length;h++){var m=a.attributes[h];if(m[0]===d&&m[1]===g){f=m[2];break}}c=M.merge(c[2],this.indices,f,a.indices);if(!c)throw Error();b.push([d,g,c])}for(e=0;e<a.attributes.length;e++){f=null;m=a.attributes[e];for(h=
0;h<this.attributes.length;h++)if(c=this.attributes[h],m[0]===c[0]&&m[1]===c[1]){f=c;break}if("undefined"===typeof f||null===f){c=M.merge(null,this.indices,m[2],a.indices);if(!c)throw Error();b.push([m[0],m[1],c])}}a=M.makeIndices(this.indices.length+a.indices.length);this._bounds=null;this.attributes=b;this.setIndices(a);return this};u.prototype.transform=function(a){var b=this.getAttribute(H3DU.Semantic.POSITION);if(!b)return this;var c=this.getAttribute(H3DU.Semantic.NORMAL),d=!(1===a[0]&&0===
a[1]&&0===a[2]&&0===a[4]&&1===a[5]&&0===a[6]&&0===a[8]&&0===a[9]&&1===a[10]),e=null;"undefined"!==typeof c&&null!==c&&d&&(e=H3DU.Math.mat4inverseTranspose3(a));var f=b.count();c&&(f=Math.min(f,c.count()));for(var g=[0,0,0],h=[0,0,0],m=0;m<f;m++){b.getVec(m,g);var n=H3DU.Math.mat4projectVec3(a,g[0],g[1],g[2]);b.setVec(m,n);c&&d&&"undefined"!==typeof e&&null!==e&&(c.getVec(m,h),n=H3DU.Math.mat3transform(e,h[0],h[1],h[2]),H3DU.Math.vec3normalizeInPlace(n),c.setVec(m,n))}this._bounds=null;return this};
u._addLine=function(a,b,c,d){if(c<d){var e=c;c=d;d=e}(e=b[c])?0>e.indexOf(d)&&(e.push(d),a.push(c,d)):(b[c]=[d],a.push(c,d))};u.prototype.toWireFrame=function(){return(new u).merge(this).wireFrame()};u.prototype.wireFrame=function(){if(this.primitiveType()!==H3DU.Mesh.TRIANGLES)return this;for(var a=[],b={},c=0;c<this.indices.length;c+=3){var d=this.indices[c],e=this.indices[c+1],f=this.indices[c+2];u._addLine(a,b,d,e);u._addLine(a,b,e,f);u._addLine(a,b,f,d)}return this.setIndices(a).setPrimitiveType(H3DU.Mesh.LINES)};
u.prototype.getBounds=function(){if(!this._bounds){var a=!0,b=Number.POSITIVE_INFINITY,b=[b,b,b,-b,-b,-b],c=this.getAttribute(H3DU.Semantic.POSITION,0);if(!c)return b;for(var d=[],e=[0,0,0],f=this.primitiveCount(),g=0;g<f;g++){this.vertexIndices(g,d);for(var h=0;h<d.length;h++){var m=c.getVec(d[h],e);a?(a=!1,b[0]=b[3]=m[0],b[1]=b[4]=m[1],b[2]=b[5]=m[2]):(b[0]=Math.min(b[0],m[0]),b[3]=Math.max(b[3],m[0]),b[1]=Math.min(b[1],m[1]),b[4]=Math.max(b[4],m[1]),b[2]=Math.min(b[2],m[2]),b[5]=Math.max(b[5],
m[2]))}b.push([])}this._bounds=b.slice(0,6);return b}return this._bounds.slice(0,6)};u.prototype.primitiveType=function(){return this.format};u.prototype.vertexCount=function(){return this.indices.length};u._resolveSemantic=function(a,b){if("number"===typeof a)return[a,b|0];var c=u._wellKnownAttributes[a];if("undefined"===typeof c||null===c){var d=a.indexOf("_");if(0>d)return null;c=u._wellKnownAttributes[a.substr(0,d)];if("undefined"===typeof c||null===c)return null;d=a.substr(d+1);return 5>=d.length&&
/^\d$/.test(d)?[c,parseInt(d,10)]:null}return[c,0]};u._wellKnownAttributes={POSITION:0,TEXCOORD:2,TEXCOORD_0:2,NORMAL:1,COLOR:3,JOINT:4,WEIGHT:5,JOINTS:4,WEIGHTS:5,TANGENT:6,BITANGENT:7};var E={POSITION:0,NORMAL:1,TEXCOORD:2,COLOR:3,JOINT:4,WEIGHT:5,TANGENT:6,BITANGENT:7,CUSTOM:8,MODEL:101,VIEW:102,PROJECTION:103,MODELVIEW:104,MODELVIEWPROJECTION:105,MODELVIEWINVERSETRANSPOSE:106,VIEWINVERSE:107,JOINTMATRIX:108},l=function(a,b,c){this._initialize(a,b,c);this._elementsDefined=0;this.currentMode=-1;
this.normal=[0,0,0];this.color=[0,0,0];this.tangent=[0,0,0];this.bitangent=[0,0,0];this.texCoord=[0,0]};l._modeToPrimitiveType=function(a){return a===l.LINES||a===l.LINE_STRIP?l.LINES:a===l.POINTS?l.POINTS:l.TRIANGLES};l._isCompatibleMode=function(a,b){return l._modeToPrimitiveType(a)===l._modeToPrimitiveType(b)};l.prototype.mode=function(a){if(0>a)throw Error("invalid mode");if(-1===this.currentMode){var b=0,c=l._modeToPrimitiveType(a);c===l.LINES?b|=l.LINES_BIT:c===l.POINTS&&(b|=l.POINTS_BIT);this._initialize([],
[],b);this.currentMode=a}else if(l._isCompatibleMode(this.currentMode,a))this.newPrimitive(),this.currentMode=a;else throw Error("Storing a different primitive mode in this mesh is no longer supported");return this};l.prototype.normal3=function(a,b,c){"number"===typeof a&&"number"===typeof b&&"number"===typeof c?(this.normal[0]=a,this.normal[1]=b,this.normal[2]=c):(this.normal[0]=a[0],this.normal[1]=a[1],this.normal[2]=a[2]);this._elementsDefined|=l.NORMALS_BIT;return this};l.prototype.color3=function(a,
b,c){"string"===typeof a?(a=H3DU.toGLColor(a),this.color[0]=a[0],this.color[1]=a[1],this.color[2]=a[2]):"number"===typeof a&&"number"===typeof b&&"number"===typeof c?(this.color[0]=a,this.color[1]=b,this.color[2]=c):(this.color[0]=a[0],this.color[1]=a[1],this.color[2]=a[2]);this._elementsDefined|=l.COLORS_BIT;return this};l.prototype.texCoord2=function(a,b){"number"===typeof a&&"number"===typeof b?(this.texCoord[0]=a,this.texCoord[1]=b):(this.texCoord[0]=a[0],this.texCoord[1]=a[1]);this._elementsDefined|=
l.TEXCOORDS_BIT;return this};l.prototype.vertex3=function(a,b,c){"undefined"===typeof a||null===a||"undefined"!==typeof b&&null!==b||"undefined"!==typeof c&&null!==c?this._vertex3(a,b,c):"number"!==typeof a?this._vertex3(a[0],a[1],a[2]):this._vertex3(a,a,a);return this};l.prototype.vertex2=function(a,b){return"undefined"===typeof a||null===a||"undefined"!==typeof b&&null!==b?this.vertex3(a,b,0):"number"!==typeof a?this.vertex3(a[0],a[1],0):this.vertex3(a,a,0)};l.prototype.setVertex=function(a,b,c,
d){if(0>a)return this;"undefined"===typeof c&&"undefined"===typeof d&&(c=b[1],d=b[2],b=b[0]);var e=this.vertexCount();a<e&&(a*=this.getStride(),this.vertices[a]=b,this.vertices[a+1]=c,this.vertices[a+2]=d);return this};l.prototype.setVertexNormal=function(a,b,c,d){if(0>a)return this;"undefined"===typeof c&&"undefined"===typeof d&&(c=b[1],d=b[2],b=b[0]);var e=this.vertexCount();a<e&&(this._rebuildVertices(l.NORMALS_BIT),a*=this.getStride(),a+=l._normalOffset(this.attributeBits),this.vertices[a]=b,
this.vertices[a+1]=c,this.vertices[a+2]=d);return this};l.prototype.getVertex=function(a){if(0>a)return null;var b=this.vertexCount();return a<b?(this._rebuildVertices(l.NORMALS_BIT),a*=this.getStride(),this.vertices.slice(a,a+3)):null};l.prototype.getVertexNormal=function(a){var b=this.vertexCount();return a<b?(this._rebuildVertices(l.NORMALS_BIT),a*=this.getStride(),a+=l._normalOffset(this.attributeBits),this.vertices.slice(a,a+3)):null};l.prototype.vertexCount=function(){return this.vertices.length/
this.getStride()};l._initVertices=function(a,b){if(0===(b&(l.TANGENTS_BIT|l.BITANGENTS_BIT)))return a;var c=l._getStride(b),d=c;0!==(b&l.TANGENTS_BIT)&&(d+=3);0!==(b&l.BITANGENTS_BIT)&&(d+=3);for(var e=[],f=0;f<a.length;f+=d)for(var g=0;g<c;g++)e.push(a[f+g]);return e};l._initTangents=function(a,b){if(0===(b&(l.TANGENTS_BIT|l.BITANGENTS_BIT)))return[];var c=l._getStride(b),d=c;0!==(b&l.TANGENTS_BIT)&&(d+=3);0!==(b&l.BITANGENTS_BIT)&&(d+=3);for(var e=[],f=0;f<a.length;f+=d){var g=0,h=0,m=0,n=0,k=0,
K=0,q=f+c;0!==(b&l.TANGENTS_BIT)&&(g=a[q],h=a[q+1],m=a[q+2],q+=3);0!==(b&l.BITANGENTS_BIT)&&(n=a[q],k=a[q+1],K=a[q+2]);e.push(g,h,m,n,k,K)}return e};l.prototype._initialize=function(a,b,c){this.attributeBits="undefined"===typeof c||null===c?0:c;a=a||[];this.vertices=l._initVertices(a,this.attributeBits);this.indices=b||[];this.tangents=l._initTangents(a,this.attributeBits);this.startIndex=0;this.primitiveData=[0,0,0,0];this.primitiveIndex=0;this.primitiveOdd=!1;b=c&l.PRIMITIVES_BITS;if(0!==b&&b!==
l.LINES_BIT&&b!==l.POINTS_BIT)throw Error("invalid format");this.getStride=function(){return l._getStride(this.attributeBits)};this.newPrimitive=function(){this.primitiveIndex=0;this.primitiveOdd=!1;return this};this.primitiveType=function(){var a=l.TRIANGLES;0!==(this.attributeBits&l.LINES_BIT)&&(a=l.LINES);0!==(this.attributeBits&l.POINTS_BIT)&&(a=l.POINTS);return a};this._rebuildVertices=function(a){var b=this.attributeBits;a=b|a&l.ATTRIBUTES_BITS;if(a!==b){for(var c=this.getStride(),d,h,m,n=[],
k=[],K=0;K<this.vertices.length;K+=c){var q=K+3;n.push(this.vertices[K],this.vertices[K+1],this.vertices[K+2]);0!==(a&l.NORMALS_BIT)&&(0!==(b&l.NORMALS_BIT)?(d=this.vertices[q],h=this.vertices[q+1],m=this.vertices[q+2],q+=3,n.push(d,h,m)):n.push(0,0,0));0!==(a&l.COLORS_BIT)&&(0===(b&l.COLORS_BIT)?n.push(0,0,0):(d=this.vertices[q],h=this.vertices[q+1],m=this.vertices[q+2],q+=3,n.push(d,h,m)));0!==(a&l.TEXCOORDS_BIT)&&(0===(b&l.TEXCOORDS_BIT)?n.push(0,0):(d=this.vertices[q],h=this.vertices[q+1],q+=
2,n.push(d,h)));0!==(a&(l.TANGENTS_BIT|l.BITANGENTS_BIT))&&(0===(b&(l.TANGENTS_BIT|l.BITANGENTS_BIT))?k.push(0,0,0,0,0,0):(d=this.tangents[q],h=this.tangents[q+1],m=this.tangents[q+2],k.push(d,h,m),d=this.tangents[q+3],h=this.tangents[q+4],m=this.tangents[q+5],k.push(d,h,m)))}this.vertices=n;this.tangents=k;this.attributeBits=a}};this._setTriangle=function(a,b,c,g,h){this.indices.push(c,g,h)};this._vertex3=function(a,b,c){var d=this.currentMode;if(-1===d)throw Error("mode() not called");this._rebuildVertices(this._elementsDefined);
var e=this.vertices.length;this.vertices.push(a,b,c);0!==(this.attributeBits&l.NORMALS_BIT)&&this.vertices.push(this.normal[0],this.normal[1],this.normal[2]);0!==(this.attributeBits&l.COLORS_BIT)&&this.vertices.push(this.color[0],this.color[1],this.color[2]);0!==(this.attributeBits&l.TEXCOORDS_BIT)&&this.vertices.push(this.texCoord[0],this.texCoord[1]);0!==(this.attributeBits&(l.TANGENTS_BIT|l.BITANGENTS_BIT))&&(this.tangents.push(this.tangent[0],this.tangent[1],this.tangent[2]),this.tangents.push(this.bitangent[0],
this.bitangent[1],this.bitangent[2]));a=this.getStride();b=e/a;if(Math.floor(b)!==b)throw Error();this.primitiveData[this.primitiveIndex]=b;this.primitiveIndex++;d===l.QUAD_STRIP&&4<=this.primitiveIndex?(this._setTriangle(e,a,this.primitiveData[0],this.primitiveData[1],this.primitiveData[2]),this._setTriangle(e,a,this.primitiveData[2],this.primitiveData[1],this.primitiveData[3]),this.primitiveData[0]=this.primitiveData[2],this.primitiveData[1]=this.primitiveData[3],this.primitiveIndex-=2):d===l.QUADS&&
4<=this.primitiveIndex?(this._setTriangle(e,a,this.primitiveData[0],this.primitiveData[1],this.primitiveData[2]),this._setTriangle(e,a,this.primitiveData[0],this.primitiveData[2],this.primitiveData[3]),this.primitiveIndex-=4):d===l.TRIANGLES&&3<=this.primitiveIndex?(this._setTriangle(e,a,this.primitiveData[0],this.primitiveData[1],this.primitiveData[2]),this.primitiveIndex-=3):d===l.LINES&&2<=this.primitiveIndex?(this.indices.push(this.primitiveData[0],this.primitiveData[1]),this.primitiveIndex-=
2):d===l.TRIANGLE_FAN&&3<=this.primitiveIndex?(this._setTriangle(e,a,this.primitiveData[0],this.primitiveData[1],this.primitiveData[2]),this.primitiveData[1]=this.primitiveData[2],--this.primitiveIndex):d===l.LINE_STRIP&&2<=this.primitiveIndex?(this.indices.push(this.primitiveData[0],this.primitiveData[1]),this.primitiveData[0]=this.primitiveData[1],this.primitiveIndex--):d===l.POINTS?(this.indices.push(this.primitiveData[0]),this.primitiveIndex--):d===l.TRIANGLE_STRIP&&3<=this.primitiveIndex&&(this.primitiveOdd?
this._setTriangle(e,a,this.primitiveData[1],this.primitiveData[0],this.primitiveData[2]):this._setTriangle(e,a,this.primitiveData[0],this.primitiveData[1],this.primitiveData[2]),this.primitiveData[0]=this.primitiveData[1],this.primitiveData[1]=this.primitiveData[2],this.primitiveIndex--);this.primitiveOdd=!this.primitiveOdd;return this}};l.prototype.primitiveCount=function(){return 0!==(this.attributeBits&l.LINES_BIT)?Math.floor(this.indices.length/2):0!==(this.attributeBits&l.POINTS_BIT)?this.indices.length:
Math.floor(this.indices.length/3)};l.prototype.toMeshBuffer=function(){var a=new u;a.setIndices(this.indices);a.setPrimitiveType(this.primitiveType());var b=l._getStride(this.attributeBits),c=new Float32Array(this.vertices);a.setAttribute(E.POSITION,c,3,0,b);var d=l._normalOffset(this.attributeBits);0<=d&&a.setAttribute(E.NORMAL,c,3,d,b);d=l._colorOffset(this.attributeBits);0<=d&&a.setAttribute(E.COLOR,c,3,d,b);d=l._texCoordOffset(this.attributeBits);0<=d&&a.setAttribute(E.TEXCOORD,c,2,d,b);b=new Float32Array(this.tangents);
0!==(this.attributeBits&l.TANGENTS_BIT)&&a.setAttribute(E.TANGENT,b,3,0,3);0!==(this.attributeBits&l.BITANGENTS_BIT)&&a.setAttribute(E.BITANGENT,b,3,3,3);return a};l._getStride=function(a){return[3,6,6,9,5,8,8,11][a&(l.NORMALS_BIT|l.COLORS_BIT|l.TEXCOORDS_BIT)]};l._normalOffset=function(a){return[-1,3,-1,3,-1,3,-1,3][a&(l.NORMALS_BIT|l.COLORS_BIT|l.TEXCOORDS_BIT)]};l._colorOffset=function(a){return[-1,-1,3,6,-1,-1,3,6][a&(l.NORMALS_BIT|l.COLORS_BIT|l.TEXCOORDS_BIT)]};l._texCoordOffset=function(a){return[-1,
-1,-1,-1,3,6,6,9][a&(l.NORMALS_BIT|l.COLORS_BIT|l.TEXCOORDS_BIT)]};l.ATTRIBUTES_BITS=255;l.PRIMITIVES_BITS=768;l.NORMALS_BIT=1;l.COLORS_BIT=2;l.TEXCOORDS_BIT=4;l.TANGENTS_BIT=8;l.BITANGENTS_BIT=16;l.LINES_BIT=256;l.POINTS_BIT=512;l.TRIANGLES=4;l.QUAD_STRIP=8;l.QUADS=7;l.LINES=1;l.TRIANGLE_FAN=6;l.TRIANGLE_STRIP=5;l.LINE_STRIP=3;l.POINTS=0;l.prototype.enumPrimitives=function(a){var b=this.primitiveType(),c=l._normalOffset(this.attributeBits),d=l._colorOffset(this.attributeBits),e=l._texCoordOffset(this.attributeBits),
f=this.getStride(),g=this.vertices,h=3;b===l.LINES&&(h=2);b===l.POINTS&&(h=1);for(b=0;b<this.indices.length;b+=h){for(var m=[],n=0;n<h;n++){var k=this.indices[b+n]*f,K={};K.position=[g[k],g[k+1],g[k+2]];0<=c&&(K.normal=[g[k+c],g[k+c+1],g[k+c+2]]);0<=d&&(K.color=[g[k+d],g[k+d+1],g[k+d+2]]);0<=e&&(K.uv=[g[k+e],g[k+e+1]]);m.push(K)}a(m)}return this};l.prototype._carryOver=function(a){this.vertices=a.vertices;this.attributeBits=a.attributeBits;this.indices=a.indices;this.tangents=a.tangents;this.newPrimitive();
return this};l.prototype.toWireFrame=function(){return 0!==(this.attributeBits&l.PRIMITIVES_BITS)?this:l._fromMeshBuffer(this.toMeshBuffer().wireFrame(),null)};l._getValue=function(a,b,c){return a?(c[0]=0,c[1]=0,c[2]=0,a.getVec(b,c),!0):!1};l._fromMeshBufferOne=function(a,b){var c=a.getAttribute(E.POSITION),d=a.getAttribute(E.NORMAL),e=a.getAttribute(E.COLOR),f=a.getAttribute(E.TEXCOORD),g=[],h=b.color.slice(0,3),m=b.normal.slice(0,3),n=b.texCoord.slice(0,2);l._getValue(d,0,g)&&b.normal3(g);l._getValue(e,
0,g)&&b.color3(g);l._getValue(f,0,g)&&b.texCoord2(g);l._getValue(c,0,g)&&b.vertex3(g);b.color3(h).normal3(m).texCoord2(n)};l._fromMeshBuffer=function(a,b){for(var c=a.getAttribute(E.POSITION),d=a.getAttribute(E.NORMAL),e=a.getAttribute(E.COLOR),f=a.getAttribute(E.TEXCOORD),g=a.getAttribute(E.TANGENT),h=a.getAttribute(E.BITANGENT),m=a.getIndices(),n=[],k=("undefined"===typeof b||null===b?new l:b).mode(a.primitiveType()),K=0;K<m.length;K++){var q=m[K];l._getValue(d,q,n)&&k.normal3(n);l._getValue(e,
q,n)&&k.color3(n);l._getValue(f,q,n)&&k.texCoord2(n);l._getValue(g,q,n)&&k.tangent3(n);l._getValue(h,q,n)&&k.bitangent3(n);l._getValue(c,q,n)&&k.vertex3(n)}k.newPrimitive();return k};l.prototype.transform=function(a){return this._carryOver(l._fromMeshBuffer(this.toMeshBuffer().transform(a),null))};l.prototype.getBoundingBox=function(){return this.toMeshBuffer().getBounds()};l.prototype.reverseNormals=function(){return 0>l._normalOffset(this.attributeBits)?this:this._carryOver(l._fromMeshBuffer(this.toMeshBuffer().reverseNormals(),
null))};l.prototype.reverseWinding=function(){if(0!==(this.attributeBits&l.PRIMITIVES_BITS))return this;for(var a=0;a<this.indices.length;a+=3){var b=this.indices[a+2];this.indices[a+2]=this.indices[a+1];this.indices[a+1]=b}return this};l.prototype.recalcNormals=function(a,b){return this.primitiveType()===l.TRIANGLES?this._carryOver(l._fromMeshBuffer(this.toMeshBuffer().recalcNormals(a,b),null)):this};l.prototype.merge=function(a){if(a instanceof H3DU.MeshBuffer)return this.merge(l._fromMeshBuffer(a,
null));if(!(a instanceof H3DU.Mesh))throw Error();if(!l._isCompatibleMode(this.currentMode,a.currentMode))throw Error("Meshes have incompatible types");return this._carryOver(l._fromMeshBuffer(this.toMeshBuffer().merge(a.toMeshBuffer()),null))};l.prototype.setColor3=function(a,b,c){return 0>l._colorOffset(this.attributeBits)?this:"string"===typeof a?this._carryOver(l._fromMeshBuffer(this.toMeshBuffer().setColor(a),null)):this._carryOver(l._fromMeshBuffer(this.toMeshBuffer().setColor([a,b,c]),null))};
l.prototype.normalizeNormals=function(){return 0>l._normalOffset(this.attributeBits)?this:this._carryOver(l._fromMeshBuffer(this.toMeshBuffer().normalizeNormals(),null))};l.prototype.tangent3=function(a,b,c){"number"===typeof a&&"number"===typeof b&&"number"===typeof c?(this.tangent[0]=a,this.tangent[1]=b,this.tangent[2]=c):(this.tangent[0]=a[0],this.tangent[1]=a[1],this.tangent[2]=a[2]);this._elementsDefined|=l.TANGENTS_BIT;return this};l.prototype.bitangent3=function(a,b,c){"number"===typeof a&&
"number"===typeof b&&"number"===typeof c?(this.bitangent[0]=a,this.bitangent[1]=b,this.bitangent[2]=c):(this.bitangent[0]=a[0],this.bitangent[1]=a[1],this.bitangent[2]=a[2]);this._elementsDefined|=l.BITANGENTS_BIT;return this};l.prototype.recalcTangents=function(){return this.primitiveType()!==l.TRIANGLES?this:this._carryOver(l._fromMeshBuffer(this.toMeshBuffer()._recalcTangents(),null))};var C=function(){this.attributes=[];this.vertexCount=0;this.indices=[];this.mode=l.TRIANGLES},N=function(){this.attributes=
[];this.vertexCount=0;this.indices=[];this.mode=l.TRIANGLES};C._toMeshBuffer=function(a,b,c){for(var d=0,e=b.length-1;0<=e&&!(d=Math.max(d,b[e]),65536<=d);e--);var f=new u,e=65536>d?new Uint16Array(b):new Uint32Array(b);f.setPrimitiveType(c);f.setIndices(e);for(e=0;e<a.length;e++)c=a[e],f.setAttributeEx(c[0],c[1],c[3],c[2]);return f};C._blank=function(a){for(var b=[],c=0;c<a;c++)b.push(0);return b};C._resize=function(a,b){if(a[2]!==b){for(var c=a[3].length/a[2],d=Math.min(a[2],b),e=C._blank(c*b),
f=0,g=0,h=0;h<c;h++){for(var m=0;m<d;m++)e[g+m]=a[3][f+m];f+=a[2];g+=b}a[2]=b;a[3]=e}};C._addValue=function(a,b){for(var c=Math.min(b.length,a[2]),d=0;d<c;d++)a[3].push(b[d]);for(d=c;d<a[2];d++)a[3].push(0)};C._defaultEndPointsCurve=function(a){for(var b=0;b<a.length;b++){var c=a[b];if(c[0]===E.POSITION&&0===c[1]){a=c[4];if("undefined"!==typeof a.endPoints&&null!==a.endPoints)return c[4].endPoints();break}}return[0,1]};C._defaultEndPointsSurface=function(a){for(var b=0;b<a.length;b++){var c=a[b];
if(c[0]===E.POSITION&&0===c[1]){a=c[4];if("undefined"!==typeof a&&null!==a&&"undefined"!==typeof a.endPoints&&null!==a.endPoints)return c[4].endPoints();break}}return[0,1,0,1]};C._setAttribute=function(a,b,c,d,e,f){var g="undefined"===typeof f||null===f?3:f,h="undefined"!==typeof c&&null!==c;if(0>=f)throw Error("Invalid attribute size");d=u._resolveSemantic(d,"undefined"===typeof e||null===e?0:e);if("undefined"===typeof d||null===d)throw Error();for(e=0;e<a.length;e++)if(f=a[e],f[0]===d[0]&&f[1]===
d[1]){h?(f[4]=c,C._resize(f,g)):a.splice(e,1);return}h&&(b=[d[0],d[1],g,C._blank(g*b),c],a.push(b))};C._NormalSurface=function(a){this.surface=new Q(a);this.endPoints=function(){return this.surface.endPoints()};this.evaluate=function(a,c){return this.surface.normal(a,c)}};C.prototype.clearVertices=function(){this.vertexCount=0;this.indices=[];for(var a=0;a<this.attributes.length;a++)this.attributes[a][3]=[];return this};C.prototype.toMeshBuffer=function(){return C._toMeshBuffer(this.attributes,this.indices,
this.mode)};C.prototype.position=function(a,b){return this.attribute(a,E.POSITION,0,b)};C.prototype.attribute=function(a,b,c,d){C._setAttribute(this.attributes,this.vertexCount,a,b,c,d);return this};C.curveToBuffer=function(a,b,c,d,e){return(new C).position(a,3).evalCurve(b,c,d,e).toMeshBuffer()};N.prototype.clearVertices=function(){this.vertexCount=0;this.indices=[];for(var a=0;a<this.attributes.length;a++)this.attributes[a][3]=[];return this};N.prototype.toMeshBuffer=function(){return C._toMeshBuffer(this.attributes,
this.indices,this.mode)};N.prototype.position=function(a,b){return this.attribute(a,E.POSITION,0,b)};N.prototype.texCoord=function(a,b){return this.attribute(a,E.TEXCOORD,0,"undefined"===typeof b||null===b?2:b)};N.prototype.positionNormal=function(a,b){var c="undefined"!==typeof a&&null!==a?new C._NormalSurface(a):null;return this.attribute(a,E.POSITION,0,b).attribute(c,E.NORMAL,0,b)};N._TexCoord=function(a){a=(new Q(a)).endPoints();this.u1=a[0];this.v1=a[2];this.uinv=a[0]===a[1]?0:1/(a[1]-a[0]);
this.vinv=a[2]===a[3]?0:1/(a[3]-a[2]);this.evaluate=function(a,c){return[(a-this.u1)*this.uinv,(c-this.v1)*this.vinv]}};N.prototype.positionTexCoord=function(a,b){var c="undefined"!==typeof a&&null!==a?new N._TexCoord(a):null;return this.attribute(a,E.POSITION,0,b).attribute(c,E.TEXCOORD,0,2)};N.prototype.positionNormalTexCoord=function(a,b){return this.positionNormal(a,b).positionTexCoord(a,b)};N.prototype.attribute=function(a,b,c,d){C._setAttribute(this.attributes,this.vertexCount,a,b,c,d);return this};
N.surfaceToBuffer=function(a,b,c,d,e,f,g,h){return(new N).positionNormalTexCoord(a,3).evalSurface(b,c,d,e,f,d,h).toMeshBuffer()};C.prototype.evalCurve=function(a,b,c,d){b="undefined"===typeof b||null===b?24:Math.ceil(b);if(0===b)return this;if(0>b)throw Error();if("undefined"===typeof a||null===a)a=l.LINES;if("undefined"===typeof c||null===c||"undefined"===typeof d||null===d)d=C._defaultEndPointsCurve(this.attributes),c=d[0],d=d[1];var e=(d-c)/b,f=this.vertexCount;if(a===l.LINES||"undefined"===typeof a||
null===a){for(d=0;d<b;d++)this.indices.push(f+d,f+d+1);this.vertexCount+=b+1}else if(a===l.POINTS){for(d=0;d<b;d++)this.indices.push(f+d);this.vertexCount+=b+1}else return this;this.mode=a;for(d=0;d<=b;d++)for(a=c+d*e,f=0;f<this.attributes.length;f++){var g=this.attributes[f],h="undefined"!==typeof g[4]&&null!==g[4]?g[4].evaluate(a):[];C._addValue(g,h)}return this};N.prototype.evalSurface=function(a,b,c,d,e,f,g){b="undefined"===typeof b||null===b?24:Math.ceil(b);c="undefined"===typeof c||null===c?
24:Math.ceil(c);if(0===b||0===c)return this;if(0>=b)throw Error();if(0>=c)throw Error();if("undefined"===typeof a||null===a)a=l.TRIANGLES;if("undefined"===typeof d||null===d||"undefined"===typeof e||null===e||"undefined"===typeof f||null===f||"undefined"===typeof g||null===g)g=C._defaultEndPointsSurface(this.attributes),d=g[0],e=g[1],f=g[2],g=g[3];if(a!==l.TRIANGLES&&a!==l.LINES&&a!==l.POINTS)return this;var h,m,n,k=(e-d)/b,K=(g-f)/c;g=this.vertexCount;this.vertexCount+=(c+1)*(b+1);for(e=0;e<=c;e++)for(n=
0;n<=b;n++){h=n*k+d;m=e*K+f;for(var q=0;q<this.attributes.length;q++){var v=this.attributes[q],A="undefined"!==typeof v[4]&&null!==v[4]?v[4].evaluate(h,m):[];C._addValue(v,A)}}this.mode=a;if(a===l.TRIANGLES)for(a=b+1,e=0;e<b;e++)for(n=0;n<c;n++)d=n*a+e+g,f=d+a,k=d+1,h=f+1,this.indices.push(d,f,k),this.indices.push(k,f,h);else if(a===l.POINTS)for(b=this.vertexCount,e=g;e<b;e++)this.indices.push(e);else if(a===l.LINES)for(a=b+1,e=0;e<=b;e++)for(n=0;n<=c;n++)f=n*a+e+g,n<c&&(k=f+a,this.indices.push(f,
k)),e<b&&(k=f+1,this.indices.push(k,f));return this};var X=function(a){this.curves=[];this.curvesEp=[];this.runningCurveStart=[];for(var b=0;b<a.length;b++)this.curves[b]=a[b]instanceof w?a[b]:new w(a[b]),this.curvesEp[b]=this.curves[b].endPoints(),this.runningCurveStart[b]=0===b?0:Number.NaN};X.prototype=Object.create(w.prototype);X.prototype.constructor=X;X.prototype.endPoints=function(){return[0,this.curves.length]};X.prototype.getCurves=function(){return this.curves};X.prototype._getRunningCurveStart=
function(a){if(0===a)return 0;if(isNaN(this.runningCurveStart[a]))for(var b=1;b<=a;b++)isNaN(this.runningCurveStart[b])&&(this.runningCurveStart[b]=this.runningCurveStart[b-1]+this.curves[b-1].arcLength(this.curvesEp[b-1][1]));return this.runningCurveStart[a]};X.prototype._getCurveAndPoint=function(a){var b;0>a?a=b=0:a>=this.curves.length?(b=this.curves.length-1,a=1):(b=Math.floor(a),a-=b);var c=this.curvesEp[b];return[b,c[0]+(c[1]-c[0])*a]};X.prototype.arcLength=function(a){if(0>=a)return 0;a=this._getCurveAndPoint(a);
return this._getRunningCurveStart(a[0])+this.curves[a[0]].arcLength(a[1])};X.prototype.evaluate=function(a){a=this._getCurveAndPoint(a);return this.curves[a[0]].evaluate(a[1])};X.prototype.velocity=function(a){a=this._getCurveAndPoint(a);return this.curves[a[0]].velocity(a[1])};r.prototype=Object.create(w.prototype);r.prototype.constructor=r;r.WEIGHTED_BIT=1;r.DIVIDE_BIT=2;r.HOMOGENEOUS_BIT=4;r.WEIGHTED_DIVIDE_BITS=3;r._checkKnots=function(a,b){for(var c=1;c<a.length;c++)if(a[c]<a[c-1])throw Error();
for(c=1;c<a.length-2-b;c++)if(a[c+b]<=a[c])throw Error();if(a[0]===a[a.length-1]||a[0]>=a[b+1])throw Error();if(a[a.length-2-b]>=a[a.length-1])throw Error();if(b+1>=a.length)throw Error();};r._nfunc=function(a,b,c,d){if(0===b)return d[a]<=c&&c<d[a+1]?1:0;if(d[a]>c||d[a]===d[a+b]&&d[a+b+1]===d[a+1]||d[a+b+1]<c)return 0;var e=d[a]===d[a+b]?0:r._nfunc(a,b-1,c,d),f=d[a+b+1]===d[a+1]?0:r._nfunc(a+1,b-1,c,d);if(0===e+f)return 0;var g=0;if(0!==e)var h=d[a+b]-d[a],g=g+(c-d[a])*e*(0===h?1:1/h);0!==f&&(h=d[a+
b+1]-d[a+1],g+=(d[a+b+1]-c)*f*(0===h?1:1/h));return g};r._getFactors=function(a,b,c,d,e){for(var f=1,g=1,h=0;h<d;h++)e[h]=0;for(h=1;h<a.length;h++)if(a[h]===a[0])f+=1;else break;for(h=a.length-2;0<=h;h--)if(a[h]===a[a.length-1])g+=1;else break;if(b>=a[a.length-1-c]&&a[a.length-1-c]===a[a.length-1])e[d-1]=1;else if(f!==c+1||g!==c+1)for(h=0;h<d;h++)e[h]=r._nfunc(h,c,b,a);else if(b<=a[c])e[0]=1;else if(b>=a[a.length-1-c])e[d-1]=1;else{d=-1;for(h=0;h<=a.length;h++)if(a[h]<=b&&b<a[h+1]){d=h;break}if(!(0>
d))for(var f=a[d+1]-b,g=a[d],m=b-g,n=e[d]=1;n<=c;n++){e[d-n]=e[d-n+1]*f/(a[d+1]-a[d-n+1]);for(h=d-n+1;h<d;h++){var k=a[h];e[h]*=(b-k)/(a[h+n]-k);e[h]+=e[h+1]*(a[h+n+1]-b)/(a[h+n+1]-a[h+1])}e[d]*=m/(a[d+n]-g)}}};r.prototype.evaluate=function(a){var b=[];if(this.fastBezier){var c=this.controlPoints;switch(c.length){case 1:b=c[0].slice(0,c[0].length);break;case 2:for(var d=c[0].length,b=[],e=c[0],c=c[1],f=0;f<d;f++){var g=e[f];b[f]=g+(c[f]-g)*a}break;case 3:d=c[0].length;b=[];e=c[0];f=c[1];c=c[2];for(g=
0;g<d;g++)b[g]=((a-2)*a+1)*e[g]+(-2*a+2)*a*f[g]+a*a*c[g];break;case 4:for(var d=c[0].length,b=[],e=c[0],f=c[1],g=c[2],c=c[3],h=0;h<d;h++)b[h]=(((3-a)*a-3)*a+1)*e[h]+((3*a-6)*a+3)*a*f[h]+(-3*a+3)*a*a*g[h]+a*a*a*c[h]}}else if(e=this.controlPoints.length,c=this.knots.length-e-1,d=this.controlPoints[0].length,b=null,a<=this.knots[c]?this.knots[c]===this.knots[0]?b=this.controlPoints[0].slice(0,d):a=this.knots[c]:a>=this.knots[this.knots.length-1-c]&&(this.knots[this.knots.length-1-c]===this.knots[this.knots.length-
1]?b=this.controlPoints[e-1].slice(0,d):a=this.knots[this.knots.length-1-c]),"undefined"===typeof b||null===b){h=0;b=-1;for(e=0;e<this.knots.length;e++)if(f=this.knots[e],(g=a===f)&&h++,f<this.knots[e+1])if(g){b=e;break}else if(f<a&&a<this.knots[e+1]){b=e;break}if(0>b)throw Error();if(h>c)throw Error();if(h===c)b=this.controlPoints[b-c].slice(0,d);else{f=c-h;g=[];for(e=b-c;e<=b-h;e++)g.push(this.controlPoints[e]);for(h=1;h<=f;h++)for(var m=g[h-1],e=h;e<g.length;e++){for(var n=b-c+e,k=this.knots[n],
n=(a-k)/(this.knots[n+c-h+1]-k),k=g[e],l=[],q=0;q<d;q++)l[q]=m[q]*(1-n)+k[q]*n;g[e]=l;m=k}b=g[g.length-1].slice(0,d)}}0!==(this.bits&r.DIVIDE_BIT)&&(b=r._fromHomogen(b));return b};r._splitKnots=function(a,b,c){for(var d=-1,e=-1,f=[],g=[],h=0;h<a.length;h++)if(a[h]>c){e=h;break}else a[h]<c&&(d=h);if(0>d||0>e)throw Error();for(h=0;h<=d;h++)f.push(a[h]);for(h=0;h<b+1;h++)f.push(c),g.push(c);for(h=e;h<a.length;h++)g.push(a[h]);return[f,g]};r.prototype.split=function(a){var b=this.controlPoints.length,
c=this.knots.length-b-1,d=this.controlPoints[0].length,e;if(a<=this.knots[c])return[null,this];if(a>=this.knots[this.knots.length-1-c])return[this,null];var f=0,g=-1;for(e=0;e<this.knots.length;e++){var h=this.knots[e],m=a===h;m&&f++;if(h<this.knots[e+1])if(m){g=e;break}else if(h<a&&a<this.knots[e+1]){g=e;break}}if(0>g)throw Error();if(f>c)throw Error();var h=r._splitKnots(this.knots,c,a),n,m=[];if(f===c)n=this.controlPoints.slice(0,g-c+1),m=this.controlPoints.slice(g-c,this.controlPoints.length);
else{var k=c-f,l=[];for(e=g-c;e<=g-f;e++)l.push(this.controlPoints[e]);n=[];for(e=0;e<=g-c;e++)n.push(this.controlPoints[e]);for(var q=[],v=1;v<=k;v++){var A=l[v-1];for(e=v;e<l.length;e++){for(var p=g-c+e,t=this.knots[p],p=(a-t)/(this.knots[p+c-v+1]-t),t=l[e],u=[],w=0;w<d;w++)u[w]=A[w]*(1-p)+t[w]*p;l[e]=u;A=t;e===v?n.push(u):e+1===l.length&&q.push(u)}}m.push(n[n.length-1]);for(e=q.length-1;0<=e;e--)m.push(q[e]);for(e=g-f;e<b;e++)m.push(this.controlPoints[e])}a=new r(n,h[0],this.bits);b=new r(m,h[1],
this.bits);return[a,b]};r.prototype.endPoints=function(){var a=this.knots.length-this.controlPoints.length-1;return[this.knots[a],this.knots[this.knots.length-1-a]]};r.prototype.getControlPoints=function(){return this.controlPoints};r.prototype.getKnots=function(){return this.knots};r.prototype.velocity=function(a){var b=[];if(this.fastBezier){var c=this.controlPoints;switch(c.length){case 1:b=P.vecZeros(c[0].length);break;case 2:b=P.vecSub(c[1],c[0]);break;case 3:for(var b=c[0].length,d=[],e=c[0],
f=c[1],c=c[2],g=0;g<b;g++)d[g]=(2*a-2)*e[g]+(-4*a+2)*f[g]+2*a*c[g];b=d;break;case 4:for(var b=c[0].length,d=[],e=c[0],f=c[1],g=c[2],c=c[3],h=0;h<b;h++)d[h]=((-3*a+6)*a-3)*e[h]+((9*a-12)*a+3)*f[h]+(-9*a+6)*a*g[h]+3*a*a*c[h];b=d}}else{c=this.controlPoints.length;e=this.knots.length-c-1;d=this.controlPoints[0].length;r._getFactors(this.knots,a,e-1,c,this.buffer);f=[];for(g=0;g<c;g++)f[g]=0;for(a=0;a<c-1;a++)g=e*this.buffer[a+1]/(this.knots[a+e+1]-this.knots[a+1]),f[a+1]+=g,f[a]-=g;for(g=0;g<d;g++){for(a=
e=0;a<c;a++)e+=f[a]*this.controlPoints[a][g];b[g]=e}}0!==(this.bits&r.DIVIDE_BIT)&&(b=r._fromHomogen(b));return b};r._convertToHomogen=function(a){for(var b=[],c=a[0].length,d=0;d<a.length;d++){for(var e=[],f=a[d][c-1],g=0;g<c-1;g++)e[g]=a[d][g]*f;e[c-1]=f;b.push(e)}return b};r._fromHomogen=function(a){for(var b=a.length,c=1/a[b-1],d=0;d<b-1;d++)a[d]*=c;return a=a.slice(0,b-1)};J.prototype=Object.create(Q.prototype);J.prototype.constructor=J;r.clamped=function(a,b,c){return new r(a,r.clampedKnots(a.length,
b),c)};r.fromBezierCurve=function(a,b){return r.clamped(a,a.length-1,b)};r.uniform=function(a,b,c){return new r(a,r.uniformKnots(a.length,b),c)};J.clamped=function(a,b,c,d){return new J(a,r.clampedKnots(a[0].length,b),r.clampedKnots(a.length,c),d)};J.uniform=function(a,b,c,d){return new J(a,r.uniformKnots(a[0].length,b),r.uniformKnots(a.length,c),d)};r.uniformKnots=function(a,b){"object"===typeof a&&(a=a.length);var c="undefined"===typeof b||null===b?3:b;if(a<c+1)throw Error("too few control points for degree "+
c+" curve");for(var c=c+1,d=[],e=1/(a+c-1),f=0;f<a+c;f++)d.push(f*e);return d};r.clampedKnots=function(a,b){"object"===typeof a&&(a=a.length);var c="undefined"===typeof b||null===b?3:b;if(a<c+1)throw Error("too few control points for degree "+c+" curve");for(var c=c+1,d=a-c,e=[],f=0;f<c;f++)e.push(0);for(f=0;f<d;f++)e.push(1*(f+1)/(d+1));for(f=0;f<c;f++)e.push(1);return e};J.prototype.evaluate=function(a,b){var c=this.controlPoints[0][0].length,d=this.bufferU,e=this.bufferV,f,g,h,m;r._getFactors(this.knotsU,
a,this.degreeU,this.ucplen,this.bufferU);r._getFactors(this.knotsV,b,this.degreeV,this.vcplen,this.bufferV);var n=[];for(h=0;h<c;h++){for(f=m=0;f<this.ucplen;f++)for(g=0;g<this.vcplen;g++)m+=this.controlPoints[g][f][h]*d[f]*e[g];n[h]=m}0!==(this.bits&r.DIVIDE_BIT)&&(n=r._fromHomogen(n));return n};J.prototype.getControlPoints=function(){return this.controlPoints};J.prototype.getKnots=function(){return this.knots};J.prototype.tangent=function(a,b){var c=this.controlPoints[0][0].length,d=this.bufferV,
e,f,g,h;r._getFactors(this.knotsU,a,this.degreeU-1,this.ucplen,this.bufferU);r._getFactors(this.knotsV,b,this.degreeV,this.vcplen,this.bufferV);var m=[],n=[];for(g=0;g<this.ucplen;g++)n[g]=0;for(e=0;e<this.ucplen-1;e++)f=this.degreeU*this.bufferU[e+1]/(this.knotsU[e+this.degreeU+1]-this.knotsU[e+1]),n[e+1]+=f,n[e]-=f;for(g=0;g<c;g++){for(e=h=0;e<this.ucplen;e++)for(f=0;f<this.vcplen;f++)h+=this.controlPoints[f][e][g]*n[e]*d[f];m[g]=h}0!==(this.bits&r.DIVIDE_BIT)&&(m=r._fromHomogen(m));return m};J.prototype.bitangent=
function(a,b){var c=this.controlPoints[0][0].length,d=this.bufferU,e,f,g,h;r._getFactors(this.knotsU,a,this.degreeU,this.ucplen,this.bufferU);r._getFactors(this.knotsV,b,this.degreeV-1,this.vcplen,this.bufferV);var m=[],n=[];for(g=0;g<this.vcplen;g++)n[g]=0;for(e=0;e<this.vcplen-1;e++)f=this.degreeV*this.bufferV[e+1]/(this.knotsV[e+this.degreeV+1]-this.knotsV[e+1]),n[e+1]+=f,n[e]-=f;for(g=0;g<c;g++){for(e=h=0;e<this.ucplen;e++)for(f=0;f<this.vcplen;f++)h+=this.controlPoints[f][e][g]*d[e]*n[f];m[g]=
h}0!==(this.bits&r.DIVIDE_BIT)&&(m=r._fromHomogen(m));return m};J._convertToHomogen=function(a){for(var b=[],c=0;c<a.length;c++)b.push(r._convertToHomogen(a[c]));return b};J.fromBezierSurface=function(a,b){return J.clamped(a,a[0].length-1,a.length-1,b)};ja.prototype=Object.create(w.prototype);ja.prototype.constructor=ja;ja.prototype.endPoints=function(){return this.curve.endPoints()};ja.prototype.evaluate=function(a){return this.curve.evaluate(a)};ka.prototype=Object.create(Q.prototype);ka.prototype.constructor=
ka;ka.prototype.evaluate=function(a,b){return this.surface.evaluate(a,b)};ka.prototype.endPoints=function(){return this.surface.endPoints()};var B=function(a){if("undefined"===typeof a||null===a)throw Error("mesh is null");a instanceof H3DU.Mesh?this.meshBuffer=a.toMeshBuffer():a instanceof H3DU.BufferedMesh?(H3DU.Shape._meshBufferWarning||(console.warn("Using an H3DU.BufferedMesh in H3DU.Shape objects is deprecated."),H3DU.Shape._meshBufferWarning=!0),this.meshBuffer=a._toMeshBuffer()):this.meshBuffer=
a;if(!(this.meshBuffer instanceof H3DU.MeshBuffer))throw Error("Unsupported data type for mesh parameter (must be Mesh or MeshBuffer)");this.transform=new H3DU.Transform;this.material=new H3DU.PbrMaterial;this.parent=null;this.visible=!0};B.prototype.getMeshBuffer=function(){return this.meshBuffer};B._meshBufferWarning=!1;B.prototype.vertexCount=function(){return this.meshBuffer?this.meshBuffer.vertexCount():0};B.prototype.primitiveCount=function(){return this.meshBuffer?this.meshBuffer.primitiveCount():
0};B.prototype.setVisible=function(a){this.visible=!!a;return this};B.prototype.getVisible=function(){return this.visible};B.prototype.setColor=function(a,b,c,d){a=H3DU.toGLColor(a,b,c,d);this._ensureMaterial().setParams({ambient:a,diffuse:a});return this};B.prototype.setTexture=function(a){this._ensureMaterial().setParams({texture:a});return this};B.prototype.setShader=function(a){this._ensureMaterial().setParams({shader:a});return this};B.prototype._ensureMaterial=function(){if("undefined"===typeof this.material||
null===this.material)this.material=new H3DU.PbrMaterial;return this.material};B.prototype.setTextureAndColor=function(a,b,c,d,e){b=H3DU.toGLColor(b,c,d,e);this._ensureMaterial().setParams({texture:a,ambient:b,diffuse:b});return this};B.prototype.setMaterial=function(a){if("undefined"===typeof a||null===a)throw Error();if(a instanceof H3DU.Texture)throw Error("Material parameter can't directly be a Texture");this.material=a;return this};B.prototype.copy=function(){var a=new H3DU.Shape(this.meshBuffer);
a.visible=this.visible;a.parent=null;a.material=this.material.copy();a.transform=this.getTransform().copy();return a};B.prototype.getTransform=function(){return this.transform};B.prototype.getMaterial=function(){return this.material};B.prototype.getBounds=function(){if(!this.meshBuffer){var a=Number.POSITIVE_INFINITY;return[a,a,a,-a,-a,-a]}var b=this.meshBuffer.getBounds();if(H3DU.Math.boxIsEmpty(b))return b;var c=this.getMatrix();if(H3DU.Math.mat4isIdentity(c))return b.slice(0,6);if(0===c[1]&&0===
c[2]&&0===c[3]&&0===c[4]&&0===c[6]&&0===c[7]&&0===c[8]&&0===c[9]&&0===c[11]&&1===c[15]){var a=[],d=c[0],e=c[12];a[0]=d*b[0]+e;var f=c[5],g=c[13];a[1]=f*b[1]+g;var h=c[10],c=c[14];a[2]=h*b[2]+c;b=[d*b[3]+e,f*b[4]+g,h*b[5]+c];return[Math.min(a[0],b[0]),Math.min(a[1],b[1]),Math.min(a[2],b[2]),Math.max(a[0],b[0]),Math.max(a[1],b[1]),Math.max(a[2],b[2])]}a=[H3DU.Math.mat4projectVec3(c,b[0],b[1],b[2]),H3DU.Math.mat4projectVec3(c,b[0],b[1],b[5]),H3DU.Math.mat4projectVec3(c,b[0],b[4],b[2]),H3DU.Math.mat4projectVec3(c,
b[0],b[4],b[5]),H3DU.Math.mat4projectVec3(c,b[3],b[1],b[2]),H3DU.Math.mat4projectVec3(c,b[3],b[1],b[5]),H3DU.Math.mat4projectVec3(c,b[3],b[4],b[2]),H3DU.Math.mat4projectVec3(c,b[3],b[4],b[5])];b=a[0];d=[b[0],b[1],b[2],b[0],b[1],b[2]];for(e=1;8>e;e++)b=a[e],d[0]=Math.min(d[0],b[0]),d[1]=Math.min(d[1],b[1]),d[2]=Math.min(d[2],b[2]),d[3]=Math.max(d[3],b[0]),d[4]=Math.max(d[4],b[1]),d[5]=Math.max(d[5],b[2]);return d};B.prototype.isCulled=function(a){return this.meshBuffer&&this.visible?!H3DU.Math.frustumHasBox(a,
this.getBounds()):!0};B.prototype.setTransform=function(a){this.transform=a.copy();return this};B.prototype.setScale=function(a,b,c){this.getTransform().setScale(a,b,c);return this};B.prototype.setPosition=function(a,b,c){this.getTransform().setPosition(a,b,c);return this};B.prototype.setQuaternion=function(a){this.getTransform().setQuaternion(a);return this};B.prototype.getMatrix=function(){var a=this.getTransform(),b=a.isIdentity();if("undefined"===typeof this.parent||null===this.parent)a=a.getMatrix();
else var c=this.parent.getMatrix(),a=b?c:H3DU.Math.mat4isIdentity(c)?a.getMatrix():H3DU.Math.mat4multiply(c,a.getMatrix());return a};var O=function(){this._init()};O.prototype._init=function(){this.shapes=[];this.parent=null;this.visible=!0;this.transform=new H3DU.Transform};O.prototype.shapeCount=function(){return this.shapes.length};O.prototype.getShape=function(a){return"undefined"===typeof this.shapes[a]?null:this.shapes[a]};O.prototype.setShape=function(a,b){this.shapes[a]=b;return this};O.prototype.copy=
function(){var a=new H3DU.ShapeGroup;a.visible=this.visible;a.transform=this.transform.copy();for(var b=0;b<this.shapes.length;b++)a.addShape(this.shapes[b].copy());return a};O.prototype.addShape=function(a){if(!a)throw Error();a.parent=this;this.shapes.push(a);return this};O.prototype.setVisible=function(a){this.visible=!!a;return this};O.prototype.getVisible=function(){return this.visible};O.prototype.getTransform=function(){return this.transform};O.prototype.getMatrix=function(){var a=this.getTransform(),
b=a.isIdentity();if("undefined"!==typeof this.parent&&null!==this.parent)var c=this.parent.getMatrix(),a=b?H3DU.Math.mat4multiply(c,a.getMatrix()):H3DU.Math.mat4isIdentity(c)?a.getMatrix():c;else a=a.getMatrix();return a};O.prototype.setTransform=function(a){this.transform=a.copy();return this};O.prototype.setMaterial=function(a){for(var b=0;b<this.shapes.length;b++)this.shapes[b].setMaterial(a);return this};O.prototype.setTexture=function(a){for(var b=0;b<this.shapes.length;b++)this.shapes[b].setTexture(a);
return this};O.prototype.setShader=function(a){for(var b=0;b<this.shapes.length;b++)this.shapes[b].setShader(a);return this};O.prototype.removeShape=function(a){for(var b=0;b<this.shapes.length;b++)this.shapes[b]===a&&(this.shapes.splice(b,1),b--);return this};O.prototype.getBounds=function(){for(var a=Number.POSITIVE_INFINITY,a=[a,a,a,-a,-a,-a],b=!0,c=0;c<this.shapes.length;c++){var d=this.shapes[c].getBounds();H3DU.Math.boxIsEmpty(d)||(b?(a[0]=d[0],a[1]=d[1],a[2]=d[2],a[3]=d[3],a[4]=d[4],a[5]=d[5],
b=!1):(a[0]=Math.min(d[0],a[0]),a[1]=Math.min(d[1],a[1]),a[2]=Math.min(d[2],a[2]),a[3]=Math.max(d[3],a[3]),a[4]=Math.max(d[4],a[4]),a[5]=Math.max(d[5],a[5])))}return a};O.prototype.vertexCount=function(){for(var a=0,b=0;b<this.shapes.length;b++)a+=this.shapes[b].vertexCount();return a};O.prototype.primitiveCount=function(){for(var a=0,b=0;b<this.shapes.length;b++)a+=this.shapes[b].primitiveCount();return a};O.prototype.setPosition=function(a,b,c){this.transform.setPosition(a,b,c);return this};O.prototype.setQuaternion=
function(a){this.transform.setQuaternion(a);return this};O.prototype.setScale=function(a,b,c){this.transform.setScale(a,b,c);return this};var V=function(a){this.image=null;this.loadStatus=0;this.name=a;this.height=this.width=0;this.clamp=!1};V.prototype.getWidth=function(){return this.width};V.prototype.getHeight=function(){return this.height};V.prototype._toInfo=function(){return new H3DU.TextureInfo({uri:this.name,wrapS:this.clamp?33071:10497,wrapT:this.clamp?33071:10497})};V.prototype.setClamp=
function(a){this.clamp=!!a;return this};V.loadTexture=function(a,b){var c,d;if("undefined"===typeof a||null===a)throw Error();d=a instanceof H3DU.Texture?a.name:a instanceof H3DU.TextureInfo?a.uri:a;if(b&&b[d]&&d&&0<d.length){if(2===b[d].loadStatus)return Promise.resolve(b[d]);c=b[d]}else c=a instanceof H3DU.Texture?a:new H3DU.Texture(d);b&&d&&0<d.length&&(b[d]=c);return c.loadImage().then(function(a){return a},function(a){return Promise.reject(a.name)})};V.fromUint8Array=function(a,b,c){if(0>b)throw Error("width less than 0");
if(0>c)throw Error("height less than 0");if(a.length<b*c*4)throw Error("array too short for texture");var d=new H3DU.Texture("");d.image=a;d.width=Math.ceil(b);d.height=Math.ceil(c);d.loadStatus=2;return d};V.loadTga=function(a){return H3DU.loadFileFromUrl(a,"arraybuffer").then(function(a){var b=new DataView(a.data),d=b.getUint8(2);if(2!==d&&3!==d)return Promise.reject(Error("unsupported image type"));var e=b.getUint16(8,!0),f=b.getUint16(10,!0);if(0!==e||0!==f)return Promise.reject(Error("unsupported origins"));
e=b.getUint16(12,!0);f=b.getUint16(14,!0);if(0===e||0===f)return Promise.reject(Error("invalid width or height"));var g=b.getUint8(16);if(!(32===g&&2===d||24===g&&2===d||8===g&&3===d))return Promise.reject(Error("unsupported pixelsize"));var h=e*f;if(h>a.data.length)return Promise.reject(Error("size too big"));var m=new Uint8Array(4*h),n=18;if(32===g&&2===d)for(g=d=0;d<h;d++,g+=4)m[g+2]=b.getUint8(n),m[g+1]=b.getUint8(n+1),m[g]=b.getUint8(n+2),m[g+3]=b.getUint8(n+3),n+=4;else if(24===g&&2===d)for(g=
d=0;d<h;d++,g+=4)m[g+2]=b.getUint8(n),m[g+1]=b.getUint8(n+1),m[g]=b.getUint8(n+2),m[g+3]=255,n+=3;else if(8===g&&3===d)for(g=d=0;d<h;d++,g+=4){var k=b.getUint8(n);m[g]=k;m[g+1]=k;m[g+2]=k;m[g+3]=255;n++}a.data=null;return{width:e,height:f,image:m}})};V.prototype.loadImage=function(){if("undefined"!==typeof this.image&&null!==this.image)return Promise.resolve(this);var a=this;if(1===this.loadStatus)return new Promise(function(b){setTimeout(function(){b(a.loadImage())},5)});var b=this.name;a.loadStatus=
1;return/\.tga$/i.test(b)?H3DU.Texture.loadTga(b).then(function(b){a.image=b.image;a.width=b.width;a.height=b.height;a.loadStatus=2;return a},function(c){a.loadStatus=-1;return Promise.reject({name:b,error:c})}):new Promise(function(c,d){var e=new Image;e.addEventListener("load",function(b){b=b.target;a.image=b;a.width=b.width;a.height=b.height;a.loadStatus=2;e.onload=null;e.onerror=null;c(a)});e.onerror=function(c){a.loadStatus=-1;e.onload=null;e.onerror=null;d({name:b,error:c})};e.src=b})};V.prototype.dispose=
function(){this.height=this.width=0;this.name="";this.image&&("undefined"!==typeof this.image.onload&&null!==this.image.onload&&(this.image.onload=null),"undefined"!==typeof this.image.onerror&&null!==this.image.onerror&&(this.image.onerror=null));this.image=null;this.clamp=!1;this.loadStatus=0};V.prototype.getName=function(){return this.name};V._texOrString=function(a){return"string"===typeof a?new H3DU.Texture(a):a};V._texOrInfoOrString=function(a){return"undefined"===typeof a||null===a?null:"string"===
typeof a?new H3DU.Texture(a):a instanceof H3DU.TextureInfo?new H3DU.TextureInfo(a.uri):a};var la=function(a){this.textures=[];for(var b=this.loadStatus=0;6>b;b++)this.textures.push(H3DU.Texture._texOrInfoOrString(a[b]))};la.prototype.getWidth=function(){return this.textures[0].getWidth()};la.prototype.getHeight=function(){return this.textures[0].getHeight()};la.prototype.setTexture=function(a,b){if(0>a||6<=a)return this;this.textures[a]=H3DU.Texture._texOrInfoOrString(b);return this};la.prototype.getTexture=
function(a){return 0>a||6<=a?null:this.textures[a]};la.prototype.loadImage=function(){var a;if(2===this.loadStatus){for(a=0;6>a;a++)2!==this.textures[a].loadStatus&&(this.loadStatus=0);if(2===this.loadStatus)return Promise.resolve(this)}var b=[];for(a=0;6>a;a++)b.push(this.textures[a].loadImage());var c=this;c.loadStatus=1;return H3DU.getPromiseResultsAll(b).then(function(){c.loadStatus=2;return Promise.resolve(c)})};var sa=function(a){this.uri="";this.topDown=!1;this.internalFormat=this.format=6408;
this.target=3553;this.type=5121;this.magFilter=9729;this.minFilter=9987;this.wrapT=this.wrapS=10497;this.setParams("undefined"===typeof a?null:a)};sa.prototype.copyFrom=function(a){"undefined"!==typeof a&&null!==a&&(this.uri="undefined"===typeof a.uri||null===a.uri?"":a.uri,this.format="undefined"===typeof a.format||null===a.format?6408:a.format,this.internalFormat="undefined"===typeof a.internalFormat||null===a.internalFormat?6408:a.internalFormat,this.target="undefined"===typeof a.target||null===
a.target?3553:a.target,this.type="undefined"===typeof a.type||null===a.type?5121:a.type,this.magFilter="undefined"===typeof a.magFilter||null===a.magFilter?9729:a.magFilter,this.minFilter="undefined"===typeof a.minFilter||null===a.minFilter?9986:a.minFilter,this.wrapS="undefined"===typeof a.wrapS||null===a.wrapS?10497:a.wrapS,this.wrapT="undefined"===typeof a.wrapT||null===a.wrapT?10497:a.wrapT,this.topDown="undefined"===typeof a.topDown||null===a.topDown?10497:a.topDown);return this};sa.prototype.setParams=
function(a){"undefined"!==typeof a&&null!==a&&("undefined"!==typeof a.uri&&null!==a.uri&&(this.uri=a.uri),"undefined"!==typeof a.format&&null!==a.format&&(this.format=a.format),"undefined"!==typeof a.internalFormat&&null!==a.internalFormat&&(this.internalFormat=a.internalFormat),"undefined"!==typeof a.target&&null!==a.target&&(this.target=a.target),"undefined"!==typeof a.type&&null!==a.type&&(this.type=a.type),"undefined"!==typeof a.magFilter&&null!==a.magFilter&&(this.magFilter=a.magFilter),"undefined"!==
typeof a.minFilter&&null!==a.minFilter&&(this.minFilter=a.minFilter),"undefined"!==typeof a.wrapS&&null!==a.wrapS&&(this.wrapS=a.wrapS),"undefined"!==typeof a.wrapT&&null!==a.wrapT&&(this.wrapT=a.wrapT),"undefined"!==typeof a.topDown&&null!==a.topDown&&(this.topDown=a.topDown));return this};sa._texInfoOrString=function(a){return"string"===typeof a?new H3DU.TextureInfo({uri:a}):a};na.prototype.mapFrameBuffer=function(a,b){for(var c,d=0;d<this._frameBuffers.length;d++)if(c=this._frameBuffers[d],c[0]===
a&&c[1]===b){if(a.width!==c[3]||a.height!==c[4])c[2].dispose(),c[2]=new H3DU.FrameBuffer(c[1],a.width,a.height),c[3]=a.width,c[4]=a.height;return c[2]}c=new H3DU.FrameBuffer(b,a.width,a.height);this._frameBuffers.push([a,b,c,a.width,a.height]);return c};na.prototype.dispose=function(){for(var a=0;a<this._frameBuffers.length;a++)this._frameBuffers[a][2].dispose();this._frameBuffers=[]};na.prototype.bind=function(a,b,c){return"undefined"!==typeof a&&null!==a?(a=this.mapFrameBuffer(a,b),b.activeTexture(b.TEXTURE0+
c),b.bindFramebuffer(b.FRAMEBUFFER,a.buffer),b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,a.colorTexture,0),b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,a.depthbuffer),a):null};na.prototype.unbind=function(a,b){"undefined"!==typeof a&&null!==a&&(b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,null,0),b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,null),b.bindFramebuffer(b.FRAMEBUFFER,null))};var ea=
function(a,b,c){if(0>b||0>c)throw Error("width or height negative");this.context=a=a.getContext?a.getContext():a;this.textureUnit=3;this._init(a,b,c)};ea.prototype._init=function(a,b,c){this.buffer=a.createFramebuffer();this.colorTexture=a.createTexture();this.width=Math.ceil(b);this.height=Math.ceil(c);this.context.activeTexture(this.context.TEXTURE0+this.textureUnit);this.context.bindTexture(this.context.TEXTURE_2D,this.colorTexture);this.context.pixelStorei(this.context.UNPACK_FLIP_Y_WEBGL,1);
this.context.texImage2D(this.context.TEXTURE_2D,0,this.context.RGBA,this.width,this.height,0,this.context.RGBA,this.context.UNSIGNED_BYTE,null);this.context.texParameteri(this.context.TEXTURE_2D,this.context.TEXTURE_MAG_FILTER,this.context.NEAREST);this.context.texParameteri(this.context.TEXTURE_2D,this.context.TEXTURE_MIN_FILTER,this.context.NEAREST);this.context.texParameteri(this.context.TEXTURE_2D,this.context.TEXTURE_WRAP_S,this.context.CLAMP_TO_EDGE);this.context.texParameteri(this.context.TEXTURE_2D,
this.context.TEXTURE_WRAP_T,this.context.CLAMP_TO_EDGE);this.depthbuffer=this.context.createRenderbuffer();b=this.context.getParameter(a.FRAMEBUFFER_BINDING);this.context.bindFramebuffer(a.FRAMEBUFFER,this.buffer);this.context.bindRenderbuffer(a.RENDERBUFFER,this.depthbuffer);this.context.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,this.width,this.height);this.context.bindFramebuffer(a.FRAMEBUFFER,b)};ea.prototype.resize=function(a,b){a=Math.ceil(a);b=Math.ceil(b);if(a!==this.width||b!==
this.height)this.dispose(),this._init(this.context,a,b);return this};ea.prototype.getWidth=function(){return this.width};ea.prototype.getHeight=function(){return this.height};ea.prototype.getContext=function(){return this.context};ea.prototype.bind=function(){console.log("FrameBuffer bind method has no effect.");return this};ea.prototype.unbind=function(){console.log("FrameBuffer unbind method has no effect.")};ea.prototype.dispose=function(){"undefined"!==typeof this.buffer&&null!==this.buffer&&
(this.context.getParameter(this.context.FRAMEBUFFER_BINDING)===this.buffer&&this.unbind(),this.context.deleteFramebuffer(this.buffer));"undefined"!==typeof this.depthbuffer&&null!==this.depthbuffer&&this.context.deleteRenderbuffer(this.depthbuffer);"undefined"!==typeof this.colorTexture&&null!==this.colorTexture&&this.context.deleteTexture(this.colorTexture);this.colorTexture=this.depthbuffer=this.buffer=null};var W=function(){this.loadedTextures=[];this.textureImages={};this.maxAnisotropy=[];this.fbLoader=
new na};W.prototype.getTexture=function(a){var b=this.textureImages[a]||null;return b&&2!==b.loadStatus?null:this.textureImages[a]||null};W.prototype.loadTexture=function(a){return H3DU.Texture.loadTexture(a,this.textureImages)};W.prototype._setMaxAnisotropy=function(a,b){a=a.getContext?a.getContext():a;for(var c=this.maxAnisotropy,d=0;d<c.length;d++)if(c[d][0]===a)if(0<=c[d][2])a.texParameteri(b,c[d][2],c[d][1]);else return;var e=a.getExtension("EXT_texture_filter_anisotropic")||a.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||
a.getExtension("MOZ_EXT_texture_filter_anisotropic");if(e)return d=e.TEXTURE_MAX_ANISOTROPY_EXT,e=a.getParameter(e.MAX_TEXTURE_MAX_ANISOTROPY_EXT),c.push([a,e,d]),a.texParameteri(b,d,e),e;c.push([a,1,-1,null]);return 1};W.prototype.loadTexturesAll=function(a,b,c){for(var d=[],e=0;e<a.length;e++)d.push(this.loadTexture(a[e]));return H3DU.getPromiseResultsAll(d,b,c)};W.prototype.loadAndMapTexture=function(a,b){b=b.getContext?b.getContext():b;var c=this;return this.loadTexture(a).then(function(d){var e=
H3DU.TextureInfo._texInfoOrString(a);c._mapTextureWithInfo(d,e,b);return Promise.resolve(d)})};W.prototype.loadAndMapTexturesAll=function(a,b,c,d){b=b.getContext?b.getContext():b;for(var e=[],f=0;f<a.length;f++)e.push(this.loadAndMapTexture(a[f],b));return H3DU.getPromiseResultsAll(e,c,d)};W.prototype._mapTextureWithInfo=function(a,b,c){c=c.getContext?c.getContext():c;for(var d=this.loadedTextures,e=0;e<d.length;e++)if(d[e][0]===a&&d[e][1]===c)return d[e][2];b=a instanceof H3DU.CubeMap?new va(a,c):
new Z(a,b,c);d.push([a,c,b]);return b};W.prototype.loadCubeMap=function(a,b,c){var d=a;a instanceof H3DU.CubeMap||(d=new H3DU.CubeMap(a));return H3DU.TextureLoader.prototype.loadTexturesAll(d.textures,b,c).then(function(){return Promise.resolve(d)})};W.prototype.mapFrameBuffer=function(a,b){b=b.getContext?b.getContext():b;return this.fbLoader.mapFrameBuffer(a,b)};W.prototype.bindFrameBuffer=function(a,b,c){b=b.getContext?b.getContext():b;return this.fbLoader.bind(a,b,c)};W.prototype.unbindFrameBuffer=
function(a,b){b=b.getContext?b.getContext():b;this.fbLoader.unbind(a,b)};W.prototype.dispose=function(){for(var a in this.textureImages)Object.prototype.hasOwnProperty.call(this.textureImages,a)&&this.textureImages[a].dispose();a=this.loadedTextures;for(var b=0;b<a.length;b++)this.loadedTextures[b][2].dispose();"undefined"!==typeof this.fbLoader&&null!==this.fbLoader||this.fbLoader.dispose();this.fbLoader=null;this.textureImages={};this.loadedTextures=[];this.maxAnisotropy=[]};pa.prototype.resize=
function(a,b){if(0>a||0>b)throw Error("width or height negative");a=Math.ceil(a);b=Math.ceil(b);this.width=a;this.height=b;return this};pa.prototype.getWidth=function(){return this.width};pa.prototype.getHeight=function(){return this.height};var I=function(){this.scale=[1,1,1];this.position=[0,0,0];this.rotation=H3DU.Math.quatIdentity();this._matrixDirty=this.complexMatrix=!1;this._isIdentity=!0;this.matrix=H3DU.Math.mat4identity()};I.prototype.getScale=function(){return this.complexMatrix?[this.matrix[0],
this.matrix[5],this.matrix[10]]:this.scale.slice(0,3)};I.prototype.getPosition=function(){return this.complexMatrix?[this.matrix[12],this.matrix[13],this.matrix[14]]:this.position.slice(0,3)};I.prototype.getQuaternion=function(){return this.complexMatrix?H3DU.Math.quatNormalizeInPlace(H3DU.Math.quatFromMat4(this.matrix)):this.rotation.slice(0,4)};I.prototype.reset=function(){this.matrix=H3DU.Math.mat4identity();this.position=[0,0,0];this.scale=[1,1,1];this.rotation=H3DU.Math.quatIdentity();this._matrixDirty=
this.complexMatrix=!1;this._isIdentity=!0;return this};I.prototype.setMatrix=function(a){this._matrixDirty=!1;this.complexMatrix=!0;this.matrix=a.slice(0,16);this.position=[this.matrix[12],this.matrix[13],this.matrix[14]];this.rotation=H3DU.Math.quatFromMat4(this.matrix);this.rotation=H3DU.Math.quatNormalizeInPlace(this.rotation);this.scale=[this.matrix[0],this.matrix[5],this.matrix[10]];this._isIdentity=1===a[0]&&0===a[1]&&0===a[2]&&0===a[3]&&0===a[4]&&1===a[5]&&0===a[6]&&0===a[7]&&0===a[8]&&0===
a[9]&&1===a[10]&&0===a[11]&&0===a[12]&&0===a[13]&&0===a[14]&&1===a[15];return this};I.prototype.isIdentity=function(){if(this._matrixDirty)if(this.complexMatrix)this.getMatrix();else return 0===this.position[0]&&0===this.position[1]&&0===this.position[2]&&1===this.scale[0]&&1===this.scale[1]&&1===this.scale[2]&&H3DU.Math.quatIsIdentity(this.rotation);return this._isIdentity};I.prototype.resetTransform=function(){return this.reset()};I.prototype.setScale=function(a,b,c){if(this.complexMatrix)return this;
this.scale="undefined"===typeof a||null===a||"undefined"!==typeof b&&null!==b||"undefined"!==typeof c&&null!==c?[a,b,c]:"number"!==typeof a?[a[0],a[1],a[2]]:[a,a,a];this._isIdentity=this._isIdentity&&1===this.scale[0]&&1===this.scale[1]&&1===this.scale[2];this._matrixDirty=!0;return this};I.prototype.setPosition=function(a,b,c){if(this.complexMatrix)return this;this.position="undefined"===typeof a||null===a||"undefined"!==typeof b&&null!==b||"undefined"!==typeof c&&null!==c?[a,b,c]:"number"!==typeof a?
[a[0],a[1],a[2]]:[a,a,a];this._isIdentity=this._isIdentity&&0===this.position[0]&&0===this.position[1]&&0===this.position[2];this._matrixDirty=!0;return this};I.prototype.movePosition=function(a,b,c){if(this.complexMatrix)return this;"undefined"===typeof a||null===a||"undefined"!==typeof b&&null!==b||"undefined"!==typeof c&&null!==c?(this.position[0]+=a,this.position[1]+=b,this.position[2]+=c):"number"!==typeof a?(this.position[0]+=a[0],this.position[1]+=a[1],this.position[2]+=a[2]):(this.position[0]+=
a,this.position[1]+=a,this.position[2]+=a);this._isIdentity=this._isIdentity&&0===this.position[0]&&0===this.position[1]&&0===this.position[2];this._matrixDirty=!0;return this};I.prototype.setQuaternion=function(a){if(this.complexMatrix)return this;this.rotation=a.slice(0,4);H3DU.Math.quatNormalizeInPlace(this.rotation);this._matrixDirty=!0;return this};I.prototype.setRotation=function(a,b,c,d){return this.setQuaternion(H3DU.Math.quatFromAxisAngle(a,b,c,d))};I.prototype.setOrientation=function(a,
b,c,d){return this.setQuaternion(H3DU.Math.quatFromAxisAngle(a,b,c,d))};I.prototype.multQuaternion=function(a){if(this.complexMatrix)return this;this.rotation=H3DU.Math.quatNormalizeInPlace(H3DU.Math.quatMultiply(this.rotation,a));this._matrixDirty=!0;return this};I.prototype.multRotation=function(a,b,c,d){return this.multQuaternion(H3DU.Math.quatFromAxisAngle(a,b,c,d))};I.prototype.multOrientation=function(a,b,c,d){return this.multQuaternion(H3DU.Math.quatFromAxisAngle(a,b,c,d))};I.prototype.getMatrix=
function(){if(this._matrixDirty)if(this._matrixDirty=!1,H3DU.Math.quatIsIdentity(this.rotation))this.matrix=[this.scale[0],0,0,0,0,this.scale[1],0,0,0,0,this.scale[2],0,this.position[0],this.position[1],this.position[2],1],this._isIdentity=0===this.position[0]&&0===this.position[1]&&0===this.position[2]&&1===this.scale[0]&&1===this.scale[1]&&1===this.scale[2];else{this.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,this.position[0],this.position[1],this.position[2],1];this.matrix=H3DU.Math.mat4multiply(this.matrix,
H3DU.Math.quatToMat4(this.rotation));H3DU.Math.mat4scaleInPlace(this.matrix,this.scale);var a=this.matrix;this._isIdentity=1===a[0]&&0===a[1]&&0===a[2]&&0===a[3]&&0===a[4]&&1===a[5]&&0===a[6]&&0===a[7]&&0===a[8]&&0===a[9]&&1===a[10]&&0===a[11]&&0===a[12]&&0===a[13]&&0===a[14]&&1===a[15]}else if(this._isIdentity)return H3DU.Math.mat4identity();return this.matrix.slice(0,16)};I.prototype.copy=function(){var a=new H3DU.Transform;a.scale=this.scale.slice(0,this.scale.length);a.position=this.position.slice(0,
this.scale.length);a.complexMatrix=this.complexMatrix;a._matrixDirty=this._matrixDirty;a.matrix=this.matrix.slice(0,this.matrix.length);return a};var G=function(a,b){if("undefined"===typeof a||null===a)a=H3DU.ShaderInfo.getDefaultVertex();if("undefined"===typeof b||null===b)b=H3DU.ShaderInfo.getDefaultFragment();this.vertexShader=a;this.fragmentShader=b;this.disposeCalled=!1;this.uniformValues={};this.attributeSemantics={};this.attributeSemantics.position=new Uint32Array([H3DU.Semantic.POSITION,0]);
this.attributeSemantics.tangent=new Uint32Array([H3DU.Semantic.TANGENT,0]);this.attributeSemantics.bitangent=new Uint32Array([H3DU.Semantic.BITANGENT,0]);this.attributeSemantics.normal=new Uint32Array([H3DU.Semantic.NORMAL,0]);this.attributeSemantics.uv=new Uint32Array([H3DU.Semantic.TEXCOORD,0]);this.attributeSemantics.colorAttr=new Uint32Array([H3DU.Semantic.COLOR,0]);this.uniformSemantics={};this.uniformSemantics.projection=H3DU.Semantic.PROJECTION;this.uniformSemantics.world=H3DU.Semantic.MODEL;
this.uniformSemantics.inverseView=H3DU.Semantic.VIEWINVERSE;this.uniformSemantics.modelViewMatrix=H3DU.Semantic.MODELVIEW;this.uniformSemantics.normalMatrix=H3DU.Semantic.MODELVIEWINVERSETRANSPOSE};G.prototype.setUniformSemantic=function(a,b){this.uniformSemantics[a]=b;return this};G.prototype.getVertexShader=function(){return this.vertexShader};G.prototype.getFragmentShader=function(){return this.fragmentShader};G.prototype.dispose=function(){this.disposeCalled=!0};G.prototype.setSemantic=function(a,
b,c){var d=this.attributeSemantics[a],e=H3DU.MeshBuffer._resolveSemantic(b,c);if(!e)throw Error("Can't resolve "+[a,b,c]);d?(d[0]=e[0],d[1]=e[1]):this.attributeSemantics[a]=e;return this};G.prototype.copy=function(){var a=new H3DU.ShaderInfo(this.vertexShader,this.fragmentShader);a.setUniforms(this.uniformValues);for(var b in this.attributeSemantics)if(Object.prototype.hasOwnProperty.call(this.attributeSemantics,b)){var c=this.attributeSemantics[b];a.attributeSemantics[b]=c.slice(0,2)}for(b in this.uniformSemantics)Object.prototype.hasOwnProperty.call(this.uniformSemantics,
b)&&(c=this.uniformSemantics[b],a.uniformSemantics[b]=c);return a};G.prototype.setUniforms=function(a){H3DU.ShaderInfo._setUniformsInternal(a,this.uniformValues,null);return this};G._setUniformInternal=function(a,b,c,d){a=a[c];var e=b[c];if("number"===typeof a){var f=!1;"undefined"===typeof e||null===e?(b[c]=e=a,f=!0):e!==a&&(e=a,b[c]=a,f=!0);f&&d&&(d[c]=e)}else if(a instanceof H3DU.TextureInfo)"undefined"!==typeof e&&null!==e&&e instanceof H3DU.TextureInfo?e.copyFrom(a):b[c]=(new H3DU.TextureInfo).copyFrom(a);
else if(3===a.length)if(!e)b[c]=a.slice(0,a.length),d&&(d[c]=a.slice(0,a.length));else{if(e[0]!==a[0]||e[1]!==a[1]||e[2]!==a[2])e[0]=a[0],e[1]=a[1],e[2]=a[2],d&&(d[c]=e.slice(0,e.length))}else if(2===a.length)if(!e)b[c]=a.slice(0,a.length),d&&(d[c]=a.slice(0,a.length));else{if(e[0]!==a[0]||e[1]!==a[1])e[0]=a[0],e[1]=a[1],d&&(d[c]=e.slice(0,e.length))}else if(4===a.length)if(!e)b[c]=a.slice(0,a.length),d&&(d[c]=a.slice(0,a.length));else{if(e[0]!==a[0]||e[1]!==a[1]||e[2]!==a[2]||e[3]!==a[3])e[0]=a[0],
e[1]=a[1],e[2]=a[2],e[3]=a[3],d&&(d[c]=e.slice(0,e.length))}else 16===a.length?e?H3DU.ShaderInfo._copyIfDifferent(a,e,16)&&d&&(d[c]=e.slice(0,e.length)):(b[c]=a.slice(0,a.length),d&&(d[c]=a.slice(0,a.length))):9===a.length&&(e?H3DU.ShaderInfo._copyIfDifferent(a,e,9)&&d&&(d[c]=e.slice(0,e.length)):(b[c]=a.slice(0,a.length),d&&(d[c]=a.slice(0,a.length))))};G._copyIfDifferent=function(a,b,c){for(var d=0;d<c;d++)if(a[d]!==b[d]){b[d]=a[d];for(d+=1;d<c;d++)b[d]=a[d];return!0}return!1};G._setUniformsInternal=
function(a,b,c){for(var d,e=Object.keys(a),f=0;f<e.length;f++)d=e[f],H3DU.ShaderInfo._setUniformInternal(a,b,d,c)};G.fragmentShaderHeader=function(){return"#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef GL_ES\n#ifndef GL_FRAGMENT_PRECISION_HIGH\nprecision mediump float;\n#else\nprecision highp float;\n#endif\n#endif\n"};G.makeEffectFragment=function(a){var b=H3DU.ShaderInfo.fragmentShaderHeader();return b+"uniform sampler2D sampler;\nuniform vec2 textureSize;\nvarying vec2 uvVar;\nvarying vec3 colorAttrVar;\n"+
a+"\n\nvoid main() {\n // normalize coordinates to 0..1\n vec2 uv=gl_FragCoord.xy/textureSize.xy;\n gl_FragColor=textureEffect(sampler,uv,textureSize);\n}"};G.makeCopyEffect=function(){var a=H3DU.ShaderInfo.fragmentShaderHeader(),a=a+"uniform sampler2D sampler;\nvarying vec2 uvVar;\nvarying vec3 colorAttrVar;\n\n\nvoid main() {\n gl_FragColor=texture2D(sampler,uvVar);\n}";return new H3DU.ShaderInfo(H3DU.ShaderInfo.getBasicVertex(),a)};G.makeEffect=function(a){return new H3DU.ShaderInfo(H3DU.ShaderInfo.getBasicVertex(),
H3DU.ShaderInfo.makeEffectFragment(a))};G.makeInvertEffect=function(){return H3DU.ShaderInfo.makeEffect("vec4 textureEffect(sampler2D sampler, vec2 uvCoord, vec2 textureSize) {\n vec4 color=texture2D(sampler,uvCoord);\n vec4 ret; ret.xyz=vec3(1.0,1.0,1.0)-color.xyz; ret.w=color.w; return ret;\n}")};G.makeEdgeDetectEffect=function(){return H3DU.ShaderInfo.makeEffect("float luma(vec3 color) {\n return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;\n}\nconst vec4 edge_color=vec4(0.,0,0,1);\nconst vec4 back_color=vec4(1.,1,1,1);\nvec4 textureEffect(sampler2D sampler, vec2 uvCoord, vec2 textureSize) {\nfloat dx = 1.0 / float(textureSize.x);\nfloat dy = 1.0 / float(textureSize.y);\nfloat s00 = luma(texture2D(sampler, uvCoord + vec2(-dx,dy)).rgb);\nfloat s10 = luma(texture2D(sampler, uvCoord + vec2(-dx,0.0)).rgb);\nfloat s20 = luma(texture2D(sampler, uvCoord + vec2(-dx,-dy)).rgb);\nfloat s01 = luma(texture2D(sampler, uvCoord + vec2(0.0,dy)).rgb);\nfloat s21 = luma(texture2D(sampler, uvCoord + vec2(0.0,-dy)).rgb);\nfloat s02 = luma(texture2D(sampler, uvCoord + vec2(dx, dy)).rgb);\nfloat s12 = luma(texture2D(sampler, uvCoord + vec2(dx, 0.0)).rgb);\nfloat s22 = luma(texture2D(sampler, uvCoord + vec2(dx, -dy)).rgb);\nfloat sx = s00 + 2.0 * s10 + s20 - (s02 + 2.0 * s12 + s22);\nfloat sy = s00 + 2.0 * s01 + s02 - (s20 + 2.0 * s21 + s22);\nfloat dist = sx * sx + sy * sy;\nif(dist > 0.4) {\nreturn edge_color;\n} else {\nreturn back_color;\n}}")};
G.getBasicVertex=function(){return"attribute vec3 position;\n\nattribute vec2 uv;\n\nvarying vec2 uvVar;\n\n#ifdef COLORATTR\n\nattribute vec3 colorAttr;\n\nvarying vec3 colorAttrVar;\n\n#endif\n\nvoid main() {\n\nvec4 positionVec4;\n\npositionVec4.w=1.0;\n\npositionVec4.xyz=position;\n\ngl_PointSize=1.0;\n\nuvVar=uv;\n\n#ifdef COLORATTR\n\ncolorAttrVar=colorAttr;\n\n#endif\n\ngl_Position=positionVec4;\n\n}\n"};G.getDefaultVertex=function(){return"attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n#ifdef COLORATTR\nattribute vec3 colorAttr;\nvarying vec3 colorAttrVar;\n#endif\nuniform mat4 projection;\nuniform mat4 modelViewMatrix;\n#ifdef SHADING\nuniform mat3 normalMatrix; /* internal */\nuniform mat4 world;\nvarying vec4 viewPositionVar;\nvarying vec3 transformedNormalVar;\n#endif\nvarying vec2 uvVar;\nvoid main() {\nvec4 positionVec4;\npositionVec4.w=1.0;\npositionVec4.xyz=position;\ngl_PointSize=1.0;\ngl_Position=(projection*modelViewMatrix)*positionVec4;\n#ifdef COLORATTR\ncolorAttrVar=colorAttr;\n#endif\nuvVar=uv;\n#ifdef SHADING\ntransformedNormalVar=normalize(normalMatrix*normal);\nviewPositionVar=modelViewMatrix*positionVec4;\n#endif\n}"};
G.getDefaultFragment=function(){var a,b=H3DU.ShaderInfo.fragmentShaderHeader()+["#define ONE_DIV_PI 0.318309886\n#define ONE_DIV_TWOPI 0.159154943\n#define PI 3.141592654\n#define TWOPI 6.283185307\n#define saturate(f) clamp(f, 0.0, 1.0)\nvec3 tolinear(vec3 c) {\n c=saturate(c);\n bvec3 lt=lessThanEqual(c,vec3(0.03928));\n return mix(pow((0.0556+c)*0.947328534,vec3(2.4)),0.077399381*c,vec3(lt));\n}\nvec3 fromlinear(vec3 c) {\n c=saturate(c);\n bvec3 lt=lessThanEqual(c,vec3(0.00304));\n return mix(pow(c,vec3(0.41666666667))*1.0556-0.0556,12.92*c,vec3(lt));\n}\nuniform vec4 md;\n#ifdef SHADING\nstruct light {\n vec4 position;\n vec4 diffuse;\n#ifdef SPECULAR\n vec4 specular;\n#endif\n vec4 radius;\n};\nuniform vec3 sceneAmbient;",
"uniform light lights["+H3DU.Lights.MAX_LIGHTS+"];","uniform vec3 ma;\nuniform vec3 me;\n#ifdef METALNESS\nuniform float metalness;\n#endif\n#ifdef METALNESS_MAP\nuniform sampler2D metalnessMap;\n#endif\n#ifdef ROUGHNESS\nuniform float roughness;\n#endif\n#ifdef ROUGHNESS_MAP\nuniform sampler2D roughnessMap;\n#endif\n#ifdef SPECULAR_MAP\nuniform sampler2D specularMap;\n#endif\n#ifdef ENV_MAP\nuniform samplerCube envMap;\n#endif\n#ifdef ENV_EQUIRECT\nuniform sampler2D envMap;\n#endif\n#ifdef EMISSION_MAP\nuniform sampler2D emissionMap;\n#endif\n#ifdef OCCLUSION_MAP\nuniform sampler2D occlusionMap;\n#endif\nuniform mat4 inverseView;\n#ifdef NORMAL_MAP\nuniform sampler2D normalMap;\n#endif\n#ifdef SPECULAR\nuniform vec3 ms;\nuniform float mshin;\n#endif\n#endif\n#ifdef TEXTURE\nuniform sampler2D sampler;\n#endif\n#ifdef COLORATTR\nvarying vec3 colorAttrVar;\n#endif\nvarying vec2 uvVar;\n#ifdef SHADING\nvarying vec4 viewPositionVar;\nvarying vec3 transformedNormalVar;\nvec4 calcLightPower(light lt, vec4 vertexPosition) {\n vec3 sdir;\n float attenuation;\n if(lt.position.w == 0.0) { /* directional light */\n  sdir=normalize((lt.position).xyz);\n  attenuation=1.0;\n } else { /* point light */\n  vec3 vertexToLight=(lt.position-vertexPosition).xyz;\n  float dsSquared=dot(vertexToLight,vertexToLight);\n  sdir=inversesqrt(dsSquared)*vertexToLight;\n  if(lt.radius.x == 0.0) {\n    attenuation=1.0;\n  } else {\n   float radiusPow4=lt.radius.x;\n   float distPow4=dsSquared*dsSquared;\n   float attenDivisor=max(0.0001,dsSquared);\n   float cut=saturate(1.0-distPow4/radiusPow4);\n   attenuation=(cut*cut)/attenDivisor;\n  }\n }\n return vec4(sdir,attenuation);\n}\n#endif\n#ifdef PHYSICAL_BASED\n#define HABLE_TONEMAP_WHITE 1.37906425\nvec3 tonemapHable(vec3 c) {\n  vec3 c2=c*2.0;\n  return HABLE_TONEMAP_WHITE*\n    (((c2*(0.15*c2+0.05)+0.004)/\n     (c2*(0.15*c2+0.5)+0.06))-0.066666);\n}\nfloat ndf(float dotnh, float alpha) {\n float alphasq=alpha*alpha;\n float d=dotnh*dotnh*(alphasq-1.0)+1.0;\n return alphasq*ONE_DIV_PI/(d*d);\n}\nfloat gsmith(float dotnv, float dotnl, float alpha) {\n float a1=(alpha+1.0);\n float k=a1*a1*0.125;\n float invk=(1.0-k);\n return dotnl/(dotnl*invk+k)*dotnv/(dotnv*invk+k);\n}\nfloat gsmithindirect(float dotnv, float dotnl, float alpha) {\n float k=alpha*alpha*0.5;\n float invk=(1.0-k);\n return dotnl/(dotnl*invk+k)*dotnv/(dotnv*invk+k);\n}\nvec3 fresnelschlick(float dothl, vec3 f0) {\n float id=1.0-dothl;\n float idsq=id*id;\n return f0+(vec3(1.0)-f0)*idsq*idsq*id;\n}\nvec3 reflectancespec(vec3 diffuse, vec3 specular, vec3 lightDir, vec3 viewDir, vec3 n, float rough) {\n vec3 h=normalize(viewDir+lightDir);\n float dotnv=abs(dot(n,viewDir))+0.0001;\n float dotnh=saturate(dot(n,h));\n float dotnl=saturate(dot(n,lightDir));\n float dothl=saturate(dot(h,lightDir));\n vec3 ctnum=ndf(dotnh,rough)*gsmith(dotnv,dotnl,rough)*fresnelschlick(dothl,specular);\n float ctden=min(dotnl*dotnv,0.0001);\n return diffuse*ONE_DIV_PI+ctnum*0.25/ctden;\n}\n#ifndef SPECULAR\nvec3 reflectance(vec3 color, vec3 lightDir, vec3 viewDir, vec3 n, float rough, float metal) {\n vec3 h=normalize(viewDir+lightDir);\n float dothl=saturate(dot(h,lightDir));\n vec3 refl=mix(vec3(0.04),color,metal);\n vec3 fr=fresnelschlick(dothl,refl);\n vec3 refr=mix((vec3(1.0)-fr)*color,vec3(0.0),metal);\n return reflectancespec(refr, refl, lightDir, viewDir, n, rough);\n}\n#endif\n#endif\nvoid main() {\n vec3 normal;\n#ifdef TEXTURE\n   vec4 baseColor=texture2D(sampler,uvVar);\n#else\n#ifdef COLORATTR\n   vec4 baseColor;\n   baseColor.w=1.0;\n   baseColor.xyz=colorAttrVar;\n#else\n   vec4 baseColor=md;\n#endif\n#endif\n#ifdef SHADING\n#ifdef NORMAL_MAP\nvec3 pt,pb;\n#ifdef GL_OES_standard_derivatives\n#define SUPPORTS_DERIVATIVES\n#endif\n#ifdef GLSL_VERSION\n#if GLSL_VERSION>=300\n#define SUPPORTS_DERIVATIVES\n#endif\n#endif\n#ifdef SUPPORTS_DERIVATIVES\nvec3 p1p,p2p;\np1p=cross(dFdy(viewPositionVar.xyz),transformedNormalVar);\np2p=cross(transformedNormalVar,dFdx(viewPositionVar.xyz));\nvec2 u1=dFdx(uvVar);\nvec2 u2=dFdy(uvVar);\npt=u1.x*p2p+u2.x*p1p;\npb=u1.y*p2p+u2.y*p1p;\nfloat scale=1.0/sqrt(max(dot(pb,pb),dot(pt,pt)));\npt*=scale;\npb*=scale;\n#else\npt=cross(transformedNormalVar,vec3(1.0,0.0,0.0));\nif(dot(pt,pt)<0.0001) {\n   pt=cross(transformedNormalVar,vec3(0.0,1.0,0.0));\n}\npb=(cross(pt,transformedNormalVar));\npt=(cross(transformedNormalVar,pb));\n#endif\nnormal = normalize(mat3(pt,pb,transformedNormalVar)*(2.0*texture2D(normalMap,uvVar).rgb - vec3(1.0)));\n#else\nnormal = normalize(transformedNormalVar);\n#endif\nvec4 lightPowerVec;\nfloat lightCosine, specular;\nvec3 materialAmbient=tolinear(ma);\nvec3 materialDiffuse=tolinear(baseColor.rgb);\nvec3 materialEmission;\n#ifdef EMISSION_MAP\nmaterialEmission=me.rgb*texture2D(emissionMap,uvVar).rgb;\n#else\n materialEmission=me.rgb;\n#endif\n materialEmission=tolinear(materialEmission);\nfloat materialAlpha=baseColor.a;\nvec4 tview=inverseView*vec4(0.0,0.0,0.0,1.0)-viewPositionVar;\nvec3 viewDirection=normalize(tview.xyz/tview.w);\nvec3 environment=vec3(1.0);\n#ifdef PHYSICAL_BASED\nvec3 lightedColor=vec3(0.05)*materialDiffuse;\n#else\nvec3 lightedColor=sceneAmbient*materialAmbient;\n#endif\n#ifdef OCCLUSION_MAP\nlightedColor*=texture2D(occlusionMap,uvVar).r;\n#endif\n#if defined(SPECULAR) || defined(SPECULAR_MAP)\nvec3 materialSpecular;\n#endif\nvec3 spectmp, lightFactor;\nfloat rough = 0.0;\nfloat metal = 0.0;\n#ifdef SPECULAR_MAP\nmaterialSpecular=vec3(1.0);\n#endif\n#ifdef SPECULAR\nmaterialSpecular=tolinear(ms);\n#endif\n#ifdef SPECULAR_MAP\nmaterialSpecular*=tolinear(texture2D(specularMap,uvVar).rgb);\n#endif\n#ifdef ROUGHNESS_MAP\nrough=1.0;\n#endif\n#ifdef PHYSICAL_BASED\n#ifdef ROUGHNESS\nrough=roughness;\n#endif\n#else\n#ifdef SPECULAR\nrough=clamp(sqrt(2.0/(2.0+mshin)),0.0,1.0);\n#endif\n#endif\n#ifdef ROUGHNESS_MAP\nrough*=texture2D(roughnessMap,uvVar).g;\n#endif\n#ifdef INVERT_ROUGHNESS\nrough=1.0-rough;\n#endif\n#ifdef METALNESS_MAP\nmetal=1.0;\n#endif\n#ifdef METALNESS\nmetal=metalness;\n#endif\n#ifdef METALNESS_MAP\nmetal*=texture2D(metalnessMap,uvVar).b;\n#endif\n"].join("\n")+
"\n";for(a=0;a<H3DU.Lights.MAX_LIGHTS;a++)b+=["lightPowerVec=calcLightPower(lights["+a+"],viewPositionVar);","lightCosine=saturate(dot(normal,lightPowerVec.xyz));\nspectmp = vec3(greaterThan(vec3(lightCosine),vec3(0.0001)));\n#ifdef PHYSICAL_BASED","    lightFactor=spectmp*lightCosine*lightPowerVec.w*tolinear(lights["+a+"].diffuse.xyz);","#ifdef SPECULAR\n    lightedColor+=reflectancespec(materialDiffuse,materialSpecular,normalize(lightPowerVec.xyz),\n         normalize(viewDirection),normal,rough)*lightFactor;\n#else\n    lightedColor+=reflectance(materialDiffuse,normalize(lightPowerVec.xyz),\n         normalize(viewDirection),normal,rough,metal)*lightFactor;\n#endif\n#else",
"    lightedColor+=spectmp*materialDiffuse*lightCosine*lightPowerVec.w*tolinear(lights["+a+"].diffuse.xyz);","#ifdef SPECULAR\n    specular=saturate(dot(normalize(viewDirection+lightPowerVec.xyz),normal));\n    specular=pow(specular,mshin);","    lightedColor+=spectmp*materialSpecular*specular*lightPowerVec.w*tolinear(lights["+a+"].specular.xyz);","#endif\n#endif\n"].join("\n")+"\n";return b+" lightedColor+=materialEmission.rgb;\n lightedColor=fromlinear(lightedColor);\n baseColor=vec4(lightedColor,materialAlpha);\n#endif\n gl_FragColor=baseColor;\n}\n"};
ga.prototype.copy=function(){return(new H3DU.Material).setParams({ambient:this.ambient,diffuse:this.diffuse,specular:this.specular,shininess:this.shininess,emission:this.emission,texture:this.texture,specularMap:this.specularMap,normalMap:this.normalMap,emissionMap:this.emissionMap,occlusionMap:this.occlusionMap,shader:this.shader})};ga.fromBasic=function(a){return new H3DU.Material({shininess:1,specular:[0,0,0],diffuse:[0,0,0],ambient:[0,0,0],texture:null,specularMap:null,normalMap:null,emission:a,
emissionMap:null,occlusionMap:null})};ga.fromBasicTexture=function(a){return new H3DU.Material({shininess:1,specular:[0,0,0],diffuse:[0,0,0],ambient:[0,0,0],texture:null,specularMap:null,normalMap:null,emission:[0,0,0],emissionMap:a})};ga.prototype.setParams=function(a){"undefined"!==typeof a.ambient&&null!==a.ambient&&(this.ambient=H3DU.toGLColor(a.ambient),3<this.ambient.length&&(this.ambient=this.ambient.slice(0,3)));"undefined"!==typeof a.diffuse&&null!==a.diffuse&&(this.diffuse=H3DU.toGLColor(a.diffuse),
4<this.diffuse.length&&(this.diffuse=this.diffuse.slice(0,4)));"undefined"!==typeof a.specular&&null!==a.specular&&(this.specular=H3DU.toGLColor(a.specular),3<this.specular.length&&(this.specular=this.specular.slice(0,3)));"undefined"!==typeof a.emission&&null!==a.emission&&(this.emission=H3DU.toGLColor(a.emission),3<this.emission.length&&(this.emission=this.emission.slice(0,3)));"undefined"!==typeof a.shininess&&null!==a.shininess&&(this.shininess=Math.min(Math.max(0,a.shininess),128));"undefined"!==
typeof a.texture&&(this.texture=H3DU.TextureInfo._texInfoOrString(a.texture));"undefined"!==typeof a.specularMap&&(this.specularMap=H3DU.TextureInfo._texInfoOrString(a.specularMap));"undefined"!==typeof a.occlusionMap&&(this.specularMap=H3DU.TextureInfo._texInfoOrString(a.occlusionMap));"undefined"!==typeof a.normalMap&&(this.normalMap=H3DU.TextureInfo._texInfoOrString(a.normalMap));"undefined"!==typeof a.emissionMap&&(this.emissionMap=H3DU.TextureInfo._texInfoOrString(a.emissionMap));"undefined"!==
typeof a.shader&&null!==a.shader&&(this.shader=a.shader);return this};ga.fromColor=function(a,b,c,d){a=H3DU.toGLColor(a,b,c,d);return new H3DU.Material(a,a)};ga.fromTexture=function(a){return new H3DU.Material({texture:a})};oa.Specular=0;oa.Metallic=1;oa.prototype.setParams=function(a){"undefined"!==typeof a.diffuse&&null!==a.diffuse&&(this.albedo=H3DU.toGLColor(a.diffuse),4<this.albedo.length&&(this.albedo=this.albedo.slice(0,4)));"undefined"!==typeof a.albedo&&null!==a.albedo&&(this.albedo=H3DU.toGLColor(a.albedo),
4<this.albedo.length&&(this.albedo=this.albedo.slice(0,4)));"undefined"!==typeof a.specular&&null!==a.specular&&(this.specular=H3DU.toGLColor(a.specular),3<this.specular.length&&(this.specular=this.specular.slice(0,3)));"undefined"!==typeof a.emission&&null!==a.emission&&(this.emission=H3DU.toGLColor(a.emission),3<this.emission.length&&(this.emission=this.emission.slice(0,3)));"undefined"!==typeof a.texture&&null!==a.texture&&(this.albedoMap=H3DU.TextureInfo._texInfoOrString(a.texture));"undefined"!==
typeof a.albedoMap&&(this.albedoMap=H3DU.TextureInfo._texInfoOrString(a.albedoMap));"undefined"!==typeof a.specularMap&&(this.specularMap=H3DU.TextureInfo._texInfoOrString(a.specularMap));"undefined"!==typeof a.normalMap&&(this.normalMap=H3DU.TextureInfo._texInfoOrString(a.normalMap));"undefined"!==typeof a.emissionMap&&(this.emissionMap=H3DU.TextureInfo._texInfoOrString(a.emissionMap));"undefined"!==typeof a.metalnessMap&&(this.metalnessMap=H3DU.TextureInfo._texInfoOrString(a.metalnessMap));"undefined"!==
typeof a.occlusionMap&&(this.occlusionMap=H3DU.TextureInfo._texInfoOrString(a.occlusionMap));"undefined"!==typeof a.roughnessMap&&(this.roughnessMap=H3DU.TextureInfo._texInfoOrString(a.roughnessMap));"undefined"!==typeof a.metalness&&null!==a.metalness&&(this.metalness=a.metalness);"undefined"!==typeof a.invertRoughness&&null!==a.invertRoughness&&(this.invertRoughness=a.invertRoughness);"undefined"!==typeof a.roughness&&null!==a.roughness&&(this.roughness=a.roughness);"undefined"!==typeof a.shader&&
(this.shader=a.shader);return this};oa.prototype.copy=function(){return new H3DU.PbrMaterial({metalness:this.metalness,metalnessMap:this.metalnessMap,roughness:this.roughness,roughnessMap:this.roughnessMap,albedo:this.albedo,invertRoughness:this.invertRoughness,specular:this.specular,emission:this.emission,albedoMap:this.albedoMap,emissionMap:this.emissionMap,occlusionMap:this.occlusionMap,specularMap:this.specularMap,normalMap:this.normalMap,shader:this.shader})};var Y=function(){this._init()};Y.prototype._init=
function(){this.lights=[];this.sceneAmbient=[.2,.2,.2]};Y.prototype.setBasic=function(){this.lights=[(new H3DU.LightSource).setParams({ambient:[0,0,0,1],position:[0,0,1,0],diffuse:[1,1,1,1],specular:[1,1,1],radius:0})];this.sceneAmbient=[.2,.2,.2];return this};Y.MAX_LIGHTS=3;Y._createNewLight=function(a){var b=new H3DU.LightSource;0!==a&&(b.diffuse=[0,0,0,0],b.specular=[0,0,0]);return b};Y.prototype.getCount=function(){return this.lights.length};Y.prototype.getLight=function(a){var b=this.lights.length;
this.lights[a]||(this.lights[a]=H3DU.Lights._createNewLight(a));if(2<=this.lights.length-b)for(;b<this.lights.length;b++)this.lights[b]||(this.lights[b]=H3DU.Lights._createNewLight(b));return this.lights[a]};Y.prototype.setParams=function(a,b){this.getLight(a).setParams(b);return this};Y.prototype.setDirectionalLight=function(a,b,c,d){b=this.setParams(a,{position:[b[0],b[1],b[2],0]});"undefined"!==typeof c&&null!==c&&(b=b.setParams(a,{diffuse:c}));"undefined"!==typeof d&&null!==d&&(b=b.setParams(a,
{specular:d}));return b};Y.prototype.setPointLight=function(a,b,c,d){b=this.setParams(a,{position:[b[0],b[1],b[2],1]});"undefined"!==typeof c&&null!==c&&(b=b.setParams(a,{diffuse:c}));"undefined"!==typeof d&&null!==d&&(b=b.setParams(a,{specular:d}));return b};Y.prototype.setAmbient=function(a,b,c,d){this.sceneAmbient=H3DU.toGLColor(a,b,c,d);return this};var Aa=function(a,b,c,d){this.ambient=[0,0,0,1];this.position=[0,0,1,0];this.diffuse=[1,1,1,1];this.specular=[1,1,1];this.radius=0;a&&a.constructor===
Array?this.setParams({diffuse:c,position:a,specular:d,ambient:b}):"undefined"!==typeof a&&null!==a&&this.setParams(a)};Aa.prototype.setParams=function(a){"undefined"!==typeof a.ambient&&null!==a.ambient&&(this.ambient=H3DU.toGLColor(a.ambient),this.ambient=this.ambient.slice(0,4));if("undefined"!==typeof a.position&&null!==a.position){var b=a.position;this.position=[b[0],b[1],b[2],null===b[3]?0:b[3]]}"undefined"!==typeof a.specular&&null!==a.specular&&(this.specular=H3DU.toGLColor(a.specular));"undefined"!==
typeof a.diffuse&&null!==a.diffuse&&(this.diffuse=H3DU.toGLColor(a.diffuse));"undefined"!==typeof a.radius&&null!==a.radius&&(this.radius=a.radius);return this};wa.prototype.setParams=function(a){if(!a)return this;"undefined"!==typeof a.clearColor&&(this.clearColor=a.clearColor);"undefined"!==typeof a.clearDepth&&(this.clearDepth=a.clearDepth);"undefined"!==typeof a.shader&&(this.shader=a.shader);"undefined"!==typeof a.clearStencil&&(this.clearStencil=a.clearStencil);"undefined"!==typeof a.useFrameBufferSize&&
(this.useFrameBufferSize=a.useFrameBufferSize);if("undefined"!==typeof a.frameBuffer){if(a.frameBuffer instanceof H3DU.FrameBuffer)throw Error("FrameBuffer not supported");this.frameBuffer=a.frameBuffer}return this};var ia=function(){this.builder=new C};ia.prototype.vertex=function(a){this.builder.position(a);return this};ia.prototype.normal=function(a){this.builder.attribute(a,H3DU.Semantic.NORMAL,0);return this};ia.prototype.color=function(a){this.builder.attribute(a,H3DU.Semantic.COLOR,0);return this};
ia.prototype.texCoord=function(a){this.builder.attribute(a,H3DU.Semantic.TEXCOORD,0,2);return this};ia.prototype.evalOne=function(a,b){this.builder.clearVertices().evalCurve(H3DU.Mesh.POINTS,1,b,b);H3DU.Mesh._fromMeshBufferOne(this.builder.toMeshBuffer(),a);return this};ia.prototype.evalCurve=function(a,b,c,d,e){if(!a)throw Error();var f=a.color.slice(0,3),g=a.normal.slice(0,3),h=a.texCoord.slice(0,2);this.builder.clearVertices().evalCurve(b,c,d,e);H3DU.Mesh._fromMeshBuffer(this.builder.toMeshBuffer(),
a);a.color3(f).normal3(g).texCoord2(h);return this};fa.prototype.setAutoNormal=function(a){this.autoNormal=!!a;return this};fa.prototype.vertex=function(a){this.pos=a;return this};fa.prototype.normal=function(a){this.norm=a;return this};fa.prototype.color=function(a){this.builder.attribute(a,H3DU.Semantic.COLOR,0,3);return this};fa.prototype.texCoord=function(a){this.builder.attribute(a,H3DU.Semantic.TEXCOORD,0,2);return this};fa.prototype.evalOne=function(a,b,c){this.builder.clearVertices().evalSurface(H3DU.Mesh.POINTS,
1,1,b,b,c,c);H3DU.Mesh._fromMeshBufferOne(this.builder.toMeshBuffer(),a);return this};fa.prototype.evalSurface=function(a,b,c,d,e,f,g,h){if(!a)throw Error();this.autoNormal?this.builder.positionNormal(this.pos):this.builder.position(this.pos).attribute(this.norm,H3DU.Semantic.NORMAL);var m=a.color.slice(0,3),k=a.normal.slice(0,3),l=a.texCoord.slice(0,2);this.builder.clearVertices().evalSurface(b,c,d,e,f,g,h);H3DU.Mesh._fromMeshBuffer(this.builder.toMeshBuffer(),a);a.color3(m).normal3(k).texCoord2(l);
return this};var z=function(a,b,c){this._init(a,new H3DU.ShaderInfo(b,c))};z._fromShaderInfo=function(a,b){var c=new H3DU.ShaderProgram(null);c._init(a,b);return c};z.prototype._init=function(a,b){if(a){a=a.getContext?a.getContext():a;this.CURRENT_PROGRAM=35725;this.FLOAT=5126;this.shaderInfo=b;this.context=a;this.prog=H3DU.ShaderProgram._compileShaders(a,b.vertexShader,b.fragmentShader);this.uniformValues={};this.actives={};this.attributes=[];this.uniformTypes={};this.savedUniforms={};this.attributeNames=
[];this.attributeSemantics={};for(var c=Object.keys(b.attributeSemantics),d=0;d<c.length;d++)this.attributeSemantics[c[d]]=b.attributeSemantics[c[d]].slice(0,2);this.uniformSemantics={};c=Object.keys(b.uniformSemantics);for(d=0;d<c.length;d++)this.uniformSemantics[c[d]]=b.uniformSemantics[c[d]];H3DU.ShaderInfo._setUniformsInternal(this.shaderInfo.uniformValues,this.uniformValues,this.savedUniforms);if("undefined"!==typeof this.prog&&null!==this.prog){for(var e,c={},f=a.getProgramParameter(this.prog,
a.ACTIVE_ATTRIBUTES),d=0;d<f;++d)if(e=a.getActiveAttrib(this.prog,d),"undefined"!==typeof e&&null!==e){e=e.name;var g=a.getAttribLocation(this.prog,e);0<=g&&(this.attributes.push(g),c[e]=g,this.attributeNames.push([e,g]))}f=a.getProgramParameter(this.prog,a.ACTIVE_UNIFORMS);for(d=0;d<f;++d)g=this.context.getActiveUniform(this.prog,d),"undefined"!==typeof g&&null!==g&&(e=g.name,c[e]=this.context.getUniformLocation(this.prog,e),this.uniformTypes[e]=g.type);this.actives=c}}};z.prototype._addNamesWithSemantic=
function(a,b,c){for(var d in this.attributeSemantics)if(Object.prototype.hasOwnProperty.call(this.attributeSemantics,d)){var e=this.attributeSemantics[d];e[0]===b&&e[1]===c&&a.push(d)}};z.prototype._disableOthers=function(a){for(var b={},c=0;c<a.length;c++)b[a[c]]=!0;for(c=0;c<this.attributeNames.length;c++)a=this.attributeNames[c],b[a[0]]||this.context.disableVertexAttribArray(a[1])};z.prototype.dispose=function(){this.program&&this.context.deleteProgram(this.program);this.program=this.context=null;
this.actives={};this.attributes={};this.uniformTypes={};this.attributeSemantics={}};z.prototype.setSemantic=function(a,b,c){b=this.attributeSemantics[a];c=H3DU.MeshBuffer._resolveSemantic(a,c);b?(b[0]=c[0],b[1]=c[1]):this.attributeSemantics[a]=c;return null};z.prototype.getContext=function(){return this.context};z.prototype._setUniformInternal=function(a,b){var c=this.get(b);if("undefined"!==typeof c&&null!==c){var d=a[b];d instanceof H3DU.TextureInfo||("number"===typeof d?this.uniformTypes[b]===
this.FLOAT?this.context.uniform1f(c,d):this.context.uniform1i(c,d):3===d.length?this.context.uniform3fv(c,d):2===d.length?this.context.uniform2fv(c,d):4===d.length?this.context.uniform4fv(c,d):16===d.length?this.context.uniformMatrix4fv(c,!1,d):9===d.length&&this.context.uniformMatrix3fv(c,!1,d))}};z.prototype.get=function(a){a=this.actives[a];return"undefined"===typeof a||null===a?null:a};z.prototype.getUniform=function(a){var b="string"===typeof a?this.get(a):a;if(null===b||"number"===typeof b)return null;
a=this.uniformValues[a];return"undefined"===typeof a||null===a?this.context.getUniform(this.program,b):a instanceof Array?a.slice(0,a.length):a};z.prototype._setSavedUniforms=function(){var a,b,c=Object.keys(this.savedUniforms);b=c.length;for(var d=0;d<b;d++)a=c[d],this._setUniformInternal(this.savedUniforms,a);return b};z.prototype.use=function(){this.context.useProgram(this.prog);0<this._setSavedUniforms()&&(this.savedUniforms={});return this};z.prototype._update=function(){H3DU.ShaderInfo._setUniformsInternal(this.shaderInfo.uniformValues,
this.uniformValues,this.savedUniforms);return this};z.prototype.setUniforms=function(a){H3DU.ShaderInfo._setUniformsInternal(a,this.uniformValues,this.savedUniforms);this.context.getParameter(this.CURRENT_PROGRAM)===this.prog&&0<this._setSavedUniforms()&&(this.savedUniforms={});return this};z._compileShaders=function(a,b,c){function d(a,b,c){var d=a.createShader(b);a.shaderSource(d,c);a.compileShader(d);if(!a.getShaderParameter(d,a.COMPILE_STATUS)){c||(c="");c=c.split("\n");for(var e=0;e<c.length;e++)c[e]=
"/* "+(e+1)+" */   "+c[e];console.log(c.join("\n"));console.log((b===a.VERTEX_SHADER?"vertex: ":"fragment: ")+a.getShaderInfoLog(d));return null}return d}b=b&&0!==b.length?d(a,a.VERTEX_SHADER,b):null;c=c&&0!==c.length?d(a,a.FRAGMENT_SHADER,c):null;var e=null;"undefined"!==typeof b&&null!==b&&"undefined"!==typeof c&&null!==c&&(e=a.createProgram(),a.attachShader(e,b),a.attachShader(e,c),a.linkProgram(e),a.getProgramParameter(e,a.LINK_STATUS)||(console.log("link: "+a.getProgramInfoLog(e)),a.deleteProgram(e),
e=null),a.detachShader(e,b),a.detachShader(e,c));"undefined"!==typeof b&&null!==b&&a.deleteShader(b);"undefined"!==typeof c&&null!==c&&a.deleteShader(c);return e};z.makeEffectFragment=function(a){return H3DU.ShaderInfo.makeEffectFragment(a)};z.makeCopyEffect=function(){return H3DU.ShaderInfo.makeCopyEffect()};z.makeEffect=function(a,b){"undefined"!==typeof a&&null!==a&&console.warn("Unused parameter context is defined");return H3DU.ShaderInfo.makeEffect(b)};z.getInvertEffect=function(a){"undefined"!==
typeof a&&null!==a&&console.warn("Unused parameter context is defined");return H3DU.ShaderInfo.makeInvertEffect()};z.getEdgeDetectEffect=function(a){"undefined"!==typeof a&&null!==a&&console.warn("Unused parameter context is defined");return H3DU.ShaderInfo.makeEdgeDetectEffect()};z.getDefaultVertex=function(){return H3DU.ShaderInfo.getDefaultVertex()};z.getDefaultFragment=function(){return H3DU.ShaderInfo.getDefaultFragment()};var H=function(a,b){b=b.getContext?b.getContext():b;this._bounds=a instanceof
H3DU.MeshBuffer?a._bounds:a.getBoundingBox();this._initialize(a,b)};H.prototype._getArrayObjectExt=function(a){return"undefined"===typeof this.arrayObjectExt||null===this.arrayObjectExt?(this.arrayObjectExt=a.getExtension("OES_vertex_array_object"),this.arrayObjectExtContext=a,this.arrayObjectExt):this.arrayObjectExtContext===a?this.arrayObjectExt:a.getExtension("OES_vertex_array_object")};H.prototype._createVertexArray=function(a){if("undefined"!==typeof WebGL2RenderingContext&&null!==WebGL2RenderingContext&&
a instanceof WebGL2RenderingContext)a.createVertexArray();else if(a instanceof WebGLRenderingContext)return a=this._getArrayObjectExt(a),"undefined"===typeof a||null===a?null:a.createVertexArrayOES();return null};H.prototype._deleteVertexArray=function(a,b){if("undefined"!==typeof WebGL2RenderingContext&&null!==WebGL2RenderingContext&&a instanceof WebGL2RenderingContext)a.deleteVertexArray(b);else if(a instanceof WebGLRenderingContext){var c=this._getArrayObjectExt(a);"undefined"!==typeof c&&null!==
c&&c.deleteVertexArrayOES(b)}};H.prototype._bindVertexArray=function(a,b){if("undefined"!==typeof WebGL2RenderingContext&&null!==WebGL2RenderingContext&&a instanceof WebGL2RenderingContext)a.bindVertexArray(b);else if(a instanceof WebGLRenderingContext){var c=this._getArrayObjectExt(a);"undefined"!==typeof c&&null!==c&&c.bindVertexArrayOES(b)}};H.prototype._initialize=function(a,b){if("undefined"===typeof a||null===a)throw Error("mesh is null");var c=a instanceof H3DU.MeshBuffer?a:a.toMeshBuffer();
this.smb=c;this.vertsMap=new H3DU.BufferedMesh._Map;this.indices=b.createBuffer();if("undefined"===typeof this.indices||null===this.indices)throw Error("can't create face buffer");this.vao=this._createVertexArray(this.context);for(var d=c._getAttributes(),e=0;e<d.length;e++){var f=d[e][2].buffer;if(f&&!this.vertsMap.get(f)){var g=b.createBuffer();if("undefined"===typeof g||null===g)throw Error("can't create buffer");b.bindBuffer(b.ARRAY_BUFFER,g);b.bufferData(b.ARRAY_BUFFER,f,b.STATIC_DRAW);this.vertsMap.put(f,
g)}}b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.indices);b.bufferData(b.ELEMENT_ARRAY_BUFFER,c.indices,b.STATIC_DRAW);d=b.UNSIGNED_SHORT;c.indices instanceof Uint32Array?d=b.UNSIGNED_INT:c.indices instanceof Uint8Array&&(d=b.UNSIGNED_BYTE);this.type=d;this.context=b;this._lastKnownProgram=null;this._attribLocations=[];this._attribNames=[]};H.prototype._toMeshBuffer=function(){return this.smb};H.prototype._getBounds=function(){return this._bounds};H.prototype.getContext=function(){return this.context};
H.prototype.dispose=function(){if("undefined"!==typeof this.vertsMap&&null!==this.vertsMap)for(var a=this.vertsMap.values(),b=0;b<a.length;b++)a[b].dispose();"undefined"!==typeof this.indices&&null!==this.indices&&this.context.deleteBuffer(this.indices);"undefined"!==typeof this.vao&&null!==this.vao&&this._deleteVertexArray(this.context,this.vao);this._lastKnownProgram=this.vao=this.smb=this.indices=this.vertsMap=null;this._attribLocations=[];this._attribNames=[]};H.prototype._getAttribLocations=
function(a){if(this._lastKnownProgram!==a){this._lastKnownProgram=a;var b=this.smb._getAttributes();this._attribLocations=[];for(var c=0;c<b.length;c++){var d=[],e=[];a._addNamesWithSemantic(e,b[c][0],b[c][1]);for(var f=0;f<e.length;f++){var g=a.get(e[f]);if("undefined"===typeof g||null===g)g=-1;d.push(g)}this._attribLocations[c]=d;this._attribNames[c]=e}return!0}return!1};H.prototype._prepareDraw=function(a,b){var c=this._getAttribLocations(a);this.vao?this._bindVertexArray(b,this.vao):c=!0;if(c){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,
this.indices);for(var c=this.smb._getAttributes(),d=[],e=0;e<this._attribLocations.length;e++)for(var f=0;f<this._attribLocations[e].length;f++){var g=this._attribLocations[e][f];if(0<=g){var h=this.vertsMap.get(c[e][2].buffer);b.bindBuffer(b.ARRAY_BUFFER,h);b.enableVertexAttribArray(g);b.vertexAttribPointer(g,c[e][2].countPerValue,b.FLOAT,!1,4*c[e][2].stride,4*c[e][2].offset);d.push(this._attribNames[e][f])}}a._disableOthers(d)}};H.prototype.draw=function(a){var b=a.getContext();if("undefined"===
typeof this.vertsMap||null===this.vertsMap)throw Error("mesh buffer disposed");if(b!==this.context)throw Error("can't bind mesh: context mismatch");this._prepareDraw(a,b);a=b.TRIANGLES;this.smb.primitiveType()===H3DU.Mesh.LINES&&(a=b.LINES);this.smb.primitiveType()===H3DU.Mesh.POINTS&&(a=b.POINTS);b.drawElements(a,this.smb.indices.length,this.type,0);this._bindVertexArray(b,null)};H.prototype.vertexCount=function(){return this.smb.indices.length};H.prototype.primitiveCount=function(){return this.smb.primitiveCount()};
H._Map=function(){this.map=[]};H._Map.prototype.get=function(a){for(var b=0;b<this.map.length;b++)if(this.map[b][0]===a)return this.map[b][1];return null};H._Map.prototype.put=function(a,b){for(var c=0;c<this.map.length;c++)if(this.map[c][0]===a){this.map[c][1]=b;return}this.map.push([a,b])};H._Map.prototype.values=function(){for(var a=[],b=0;b<this.map.length;b++)a.push(this.map[b][1]);return a};H._MeshLoader=function(){this.meshes=[]};H._MeshLoader.prototype.draw=function(a,b){if(!(a instanceof
H3DU.MeshBuffer))throw Error("Expected H3DU.MeshBuffer");for(var c=b.getContext(),d=0;d<this.meshes.length;d++){var e=this.meshes[d];if(e[0]===a&&e[1]===c){e[2].draw(b);return}}d=new H3DU.BufferedMesh(a,b);this.meshes.push([a,c,d]);d.draw(b)};H._MeshLoader.prototype.dispose=function(){for(var a=0;a<this.meshes.length;a++)this.meshes[a][2].dispose();this.meshes=[]};t.Math=k;t.Scene3D=p;t.Batch3D=y;t.Curve=w;t.Surface=Q;t.CurveBuilder=C;t.SurfaceBuilder=N;t.PiecewiseCurve=X;t.BezierCurve=ja;t.BezierSurface=
ka;t.BSplineCurve=r;t.BSplineSurface=J;t.Shape=B;t.ShapeGroup=O;t.Texture=V;t.CubeMap=la;t.TextureInfo=sa;t.TextureLoader=W;t.FrameBufferInfo=pa;t.Transform=I;t.ShaderInfo=G;t.Material=ga;t.PbrMaterial=oa;t.Mesh=l;t.Meshes={createBox:function(a,b,c,d){a*=.5;b*=.5;c*=.5;a=[-a,-b,c,-1,0,0,1,0,-a,b,c,-1,0,0,1,1,-a,b,-c,-1,0,0,0,1,-a,-b,-c,-1,0,0,0,0,a,-b,-c,1,0,0,1,0,a,b,-c,1,0,0,1,1,a,b,c,1,0,0,0,1,a,-b,c,1,0,0,0,0,a,-b,-c,0,-1,0,1,0,a,-b,c,0,-1,0,1,1,-a,-b,c,0,-1,0,0,1,-a,-b,-c,0,-1,0,0,0,a,b,c,0,
1,0,1,0,a,b,-c,0,1,0,1,1,-a,b,-c,0,1,0,0,1,-a,b,c,0,1,0,0,0,-a,-b,-c,0,0,-1,1,0,-a,b,-c,0,0,-1,1,1,a,b,-c,0,0,-1,0,1,a,-b,-c,0,0,-1,0,0,a,-b,c,0,0,1,1,0,a,b,c,0,0,1,1,1,-a,b,c,0,0,1,0,1,-a,-b,c,0,0,1,0,0];if(d)for(d=0;d<a.length;d+=8)a[d+3]=-a[d+3],a[d+4]=-a[d+4],a[d+5]=-a[d+5];d=new Float32Array(a);return(new H3DU.MeshBuffer).setIndices([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]).setAttribute(H3DU.Semantic.POSITION,d,3,0,8).setAttribute(H3DU.Semantic.NORMAL,
d,3,3,8).setAttribute(H3DU.Semantic.TEXCOORD,d,2,6,8)},createCylinder:function(a,b,c,d,e,f,g){var h=new H3DU.Mesh;if("undefined"===typeof d||null===d)d=32;if("undefined"===typeof e||null===e)e=1;if(2>=d)throw Error("too few slices");if(1>e)throw Error("too few stacks");if(0>c)throw Error("negative height");if(0>=a&&0>=b||0===c)return h;for(var m=g?-1:1,k=[],l=[],p=H3DU.Math.PiTimes2/d,q=Math.cos(p),v=3.141592653589793>=p?Math.sqrt(1-q*q):-Math.sqrt(1-q*q),A=1,r=0,p=0;p<d;p++){var t=1*p/d;k.push(A,
r);l.push(t);t=q*A+v*r;r=q*r-v*A;A=t}k.push(k[0],k[1]);l.push(1);d*=2;if(0<c)for(q=0,v=a,a===b?(r=0,A=m):(p=a-b,A=c,r=Math.sqrt(A*A+p*p),0!==r&&(r=1/r,p*=r,A*=r),A*=m,r=p*m),m=1/e,p=0;p<e;p++){var t=q,u=p+1===e?1:(p+1)*m,w=c*t,x=c*u,D=v,y=a+(b-a)*u,q=u,v=y;h.mode(H3DU.Mesh.TRIANGLE_STRIP);h.texCoord2(1,t);h.normal3(k[0]*A,k[1]*A,r);h.vertex3(k[0]*D,k[1]*D,w);h.texCoord2(1,u);h.normal3(k[0]*A,k[1]*A,r);h.vertex3(k[0]*y,k[1]*y,x);for(var F=2,C=1;F<=d;F+=2,C++){var E=l[C],B,z;B=k[F];z=k[F+1];h.texCoord2(1-
E,t);h.normal3(B*A,z*A,r);h.vertex3(B*D,z*D,w);h.texCoord2(1-E,u);h.normal3(B*A,z*A,r);h.vertex3(B*y,z*y,x)}}h=h.toMeshBuffer();return f?h.recalcNormals(f,g):h},createLathe:function(a,b,c,d){var e=new H3DU.Mesh;if(4>a.length)throw Error("too few points");if("undefined"===typeof b||null===b)b=32;if(2>=b)throw Error("too few slices");if(0!==a.length%1)throw Error("points array length is not an even number");var f;for(f=0;f<a.length;f+=2)if(0>a[f<<1])throw Error("point's x is less than 0");var g=[],
h=[];f=H3DU.Math.PiTimes2/b;var m=Math.cos(f),k=3.141592653589793>=f?Math.sqrt(1-m*m):-Math.sqrt(1-m*m),l=1,p=0;for(f=0;f<b;f++){var q=1*f/b;g.push(l,p);h.push(q);q=m*l+k*p;p=m*p-k*l;l=q}g.push(g[0],g[1]);h.push(1);b*=2;var v=0,m=a.length/2-1,k=1/m;for(f=0;f<m;f++){var l=v,p=f+1===m?1:(f+1)*k,v=f<<1,r=a[v+1],t=a[v+3],q=Math.min(r,t),r=Math.max(r,t),t=a[v],u=a[v+2],v=p;e.mode(H3DU.Mesh.TRIANGLE_STRIP);e.texCoord2(1,l);e.vertex3(g[0]*t,g[1]*t,q);e.texCoord2(1,p);e.vertex3(g[0]*t,g[1]*u,r);for(var w=
2,y=1;w<=b;w+=2,y++){var x=h[y],D,C;D=g[w];C=g[w+1];e.texCoord2(1-x,l);e.vertex3(D*t,C*t,q);e.texCoord2(1-x,p);e.vertex3(D*u,C*u,r)}}e=e.toMeshBuffer();return e.recalcNormals(c,d)},createClosedCylinder:function(a,b,c,d,e,f,g){e=H3DU.Meshes.createCylinder(a,b,c,d,e,f,g);a=H3DU.Meshes.createDisk(0,a,d,2,!g).reverseWinding();b=H3DU.Meshes.createDisk(0,b,d,2,g);b.transform(H3DU.Math.mat4translated(0,0,c));return e.merge(a).merge(b)},createDisk:function(a,b,c,d,e){return H3DU.Meshes.createPartialDisk(a,
b,c,d,0,360,e)},createPartialDisk:function(a,b,c,d,e,f,g){var h=new H3DU.Mesh;if("undefined"===typeof c||null===c)c=32;if("undefined"===typeof d||null===d)d=1;if("undefined"===typeof e||null===e)e=0;if("undefined"===typeof f||null===f)f=360;if(2>=c)throw Error("too few slices");if(1>d)throw Error("too few loops");if(a>b)throw Error("inner greater than outer");0>a&&(a=0);0>b&&(b=0);if(0===b||0===f)return h;var m=360===f&&0===e,k=0>f?-1:1;0>f&&(f=-f);f%=360;0===f&&(f=360);var l=[],p=[],q=H3DU.Math.PiTimes2;
f=360===f?q:f*H3DU.Math.PiDividedBy180;e*=H3DU.Math.PiDividedBy180;0>k&&(f=-f);var v=f/c,k=Math.cos(v),v=0<=v&&6.283185307179586>v?3.141592653589793>=v?Math.sqrt(1-k*k):-Math.sqrt(1-k*k):Math.sin(v),r=Math.cos(e),t=0<=e&&6.283185307179586>e?3.141592653589793>=e?Math.sqrt(1-r*r):-Math.sqrt(1-r*r):Math.sin(e),u=r,w=t;for(e=0;e<=c;e++){e===c&&f===q?l.push(w,u):l.push(t,r);p.push(1*e/c);var y=k*t+v*r,r=k*r-v*t,t=y}m&&(l[0]=0,l[1]=1,l[l.length-1]=1,l[l.length-2]=0,p[0]=0,p[p.length-1]=1);c*=2;m=b-a;p=
a;g?h.normal3(0,0,-1):h.normal3(0,0,1);for(e=0;e<d;e++)if(g=p,q=a+(e+1)/d*m,f=g/b,k=q/b,p=q,v=0===e&&0===a,h.mode(v?H3DU.Mesh.TRIANGLE_FAN:H3DU.Mesh.TRIANGLE_STRIP),v)for(r=c/2,v=c,u=r;0<=v;v-=2,u--)r=l[v],t=l[v+1],v===c&&(h.texCoord2(.5*(1+r*f),.5*(1+t*f)),h.vertex3(r*g,t*g,0)),h.texCoord2(.5*(1+r*k),.5*(1+t*k)),h.vertex3(r*q,t*q,0);else for(u=v=0;v<=c;v+=2,u++)r=l[v],t=l[v+1],h.texCoord2(.5*(1+r*k),.5*(1+t*k)),h.vertex3(r*q,t*q,0),h.texCoord2(.5*(1+r*f),.5*(1+t*f)),h.vertex3(r*g,t*g,0);return h=
h.toMeshBuffer()},createTorus:function(a,b,c,d,e,f){var g=new H3DU.Mesh;if("undefined"===typeof d||null===d)d=16;if("undefined"===typeof c||null===c)c=16;if(3>d)throw Error("crosswise is less than 3");if(3>c)throw Error("lengthwise is less than 3");if(0>a||0>b)throw Error("inner or outer is less than 0");if(0===b||0===a)return g;var h=[],m=[],k,l,p,q=H3DU.Math.PiTimes2/d;p=Math.cos(q);var r=0<=q&&6.283185307179586>q?3.141592653589793>=q?Math.sqrt(1-p*p):-Math.sqrt(1-p*p):Math.sin(q);l=0;k=1;for(q=
0;q<d;q++){h.push(l,k);var t=p*l+r*k;k=p*k-r*l;l=t}h.push(h[0]);h.push(h[1]);q=H3DU.Math.PiTimes2/c;p=Math.cos(q);r=0<=q&&6.283185307179586>q?3.141592653589793>=q?Math.sqrt(1-p*p):-Math.sqrt(1-p*p):Math.sin(q);l=0;k=1;for(q=0;q<c;q++)m.push(l,k),t=p*l+r*k,k=p*k-r*l,l=t;m.push(m[0]);m.push(m[1]);for(r=0;r<c;r++){t=r/c;k=(r+1)/c;l=m[2*r];var u=m[2*r+1],w=m[2*r+2],y=m[2*r+3];g.mode(H3DU.Mesh.TRIANGLE_STRIP);for(q=0;q<=d;q++){p=q/d;var C=h[2*q],x=h[2*q+1],D=x*(b+y*a),E=C*(b+y*a),F=w*a,B=y*x,z=y*C,M=w;
g.normal3(B,z,M);g.texCoord2(p,k);g.vertex3(D,E,F);D=x*(b+u*a);E=C*(b+u*a);F=l*a;B=u*x;z=u*C;M=l;g.normal3(B,z,M);g.texCoord2(p,t);g.vertex3(D,E,F)}}g=g.toMeshBuffer();return e?g.recalcNormals(e,f):g},createPlane:function(a,b,c,d,e){var f=new H3DU.Mesh;if("undefined"===typeof a||null===a)a=1;if("undefined"===typeof b||null===b)b=1;if("undefined"===typeof c||null===c)c=1;if("undefined"===typeof d||null===d)d=1;if(0>a||0>b)throw Error("width or height is less than 0");if(0>=d||0>=c)throw Error("widthDiv or heightDiv is 0 or less");
if(0===a||0===b)return f;var g=.5*-a,h=.5*-b;e?f.normal3(0,0,-1):f.normal3(0,0,1);for(e=0;e<d;e++){f.mode(H3DU.Mesh.TRIANGLE_STRIP);var k=e/d,l=(e+1)/d,p=h+b*k,r=h+b*l;f.texCoord2(0,l);f.vertex3(g,r,0);f.texCoord2(0,k);f.vertex3(g,p,0);for(var q=0;q<c;q++){var v=(q+1)/c,t=g+a*v;f.texCoord2(v,l);f.vertex3(t,r,0);f.texCoord2(v,k);f.vertex3(t,p,0)}}return f=f.toMeshBuffer()},createSphere:function(a,b,c,d,e){return H3DU.Meshes._createCapsule(a,0,b,c,1,d,e)},createCapsule:function(a,b,c,d,e,f,g){if("undefined"===
typeof d||null===d)d=8;if(1>d)throw Error("too few stacks");return H3DU.Meshes._createCapsule(a,b,c,2*d,e,f,g)},_createCapsule:function(a,b,c,d,e,f,g){function h(a,b,c,d,e,f){a.normal3(c*b,d*b,e*b);a.vertex3(c,d,e+f)}var k=new H3DU.Mesh;if("undefined"===typeof c||null===c)c=16;if("undefined"===typeof d||null===d)d=16;if("undefined"===typeof e||null===e)e=1;if("undefined"===typeof a||null===a)a=1;if("undefined"===typeof b||null===b)b=1;if(2>d)throw Error("too few stacks");if(2>=c)throw Error("too few slices");
if(1>e&&0<b)throw Error("too few middle stacks");if(0>b)throw Error("negative length");if(0>a)throw Error("negative radius");if(0===a)return k;var l,p,r=.5*b,q=d/2,t=g?-1:1,u=[],w=[],y=[],C=[],E,x=H3DU.Math.PiTimes2/c,D=Math.cos(x),B=0<=x&&6.283185307179586>x?3.141592653589793>=x?Math.sqrt(1-D*D):-Math.sqrt(1-D*D):Math.sin(x);p=1;for(x=l=0;x<c;x++){var F=1*x/c;u.push(p,l);C.push(F);var z=D*p+B*l;l=D*l-B*p;p=z}u.push(u[0],u[1]);C.push(1);var F=2*a,F=F/(F+b),M=[],x=Math.PI/d,D=Math.cos(x);p=B=0<=x&&
6.283185307179586>x?3.141592653589793>=x?Math.sqrt(1-D*D):-Math.sqrt(1-D*D):Math.sin(x);l=D;for(x=0;x<d;x++)z=1*(x+1)/d,w.push(p),M.push(-l),y.push(z),z=D*p+B*l,l=D*l-B*p,p=z;c*=2;var D=-1,O=p=0,B=u[0];l=u[1];for(x=0;x<d;x++){var H=M[x],G=y[x];E=a*D;var z=a*H,I=x<q?-r:r,J=p,L=a*w[x],U=O,S=G;0<b&&(U=x<q?O*F:1-(1-O)*F,S=x<q?G*F:1-(1-G)*F);D=H;O=G;p=L;x===d-1||0===x?k.mode(H3DU.Mesh.TRIANGLES):(k.mode(H3DU.Mesh.TRIANGLE_STRIP),k.texCoord2(1,U),h(k,t,B*J,l*J,E,I),k.texCoord2(1,S),h(k,t,B*L,l*L,z,I));
for(var P=0,R=B,N=l,T,Q,G=2,V=1;G<=c;G+=2,V++)H=C[V],x===d-1?(T=P+.5*(H-P),k.texCoord2(1-P,U),h(k,t,R*J,N*J,E,I),k.texCoord2(1-T,S),h(k,t,B*L,l*L,z,I),T=u[G],Q=u[G+1],k.texCoord2(1-H,U),h(k,t,T*J,Q*J,E,I),R=T,N=Q,P=H):0===x?(T=P+.5*(H-P),k.texCoord2(1-T,U),h(k,t,B*J,l*J,E,I),k.texCoord2(1-P,S),h(k,t,R*L,N*L,z,I),T=u[G],Q=u[G+1],k.texCoord2(1-H,S),h(k,t,T*L,Q*L,z,I),R=T,N=Q,P=H):(T=u[G],Q=u[G+1],k.texCoord2(1-H,U),h(k,t,T*J,Q*J,E,I),k.texCoord2(1-H,S),h(k,t,T*L,Q*L,z,I));if(x+1===q&&0<b)for(I=.5*F,
J=2*r,P=1-I,R=1-F,N=0;N<e;N++){E=-r+(0===N?0:J*N/e);var W=N===e-1?r:-r+J*(N+1)/e,U=I+(0===N?0:R*N/e),S=N===e-1?P:I+R*(N+1)/e;k.mode(H3DU.Mesh.TRIANGLE_STRIP);k.texCoord2(1,U);h(k,t,B*L,l*L,z,E);k.texCoord2(1,S);h(k,t,B*L,l*L,z,W);G=2;for(V=1;G<=c;G+=2,V++)H=C[V],T=u[G],Q=u[G+1],k.texCoord2(1-H,U),h(k,t,T*L,Q*L,z,E),k.texCoord2(1-H,S),h(k,t,T*L,Q*L,z,W)}}k=k.toMeshBuffer();return f?k.recalcNormals(f,g):k.normalizeNormals()},createPointedStar:function(a,b,c,d){var e=new H3DU.Mesh;if(2>a||0>b||0>c||
0>=b&&0>=c)return e;e.mode(H3DU.Mesh.TRIANGLE_FAN);var f=0,g=0,h=1/Math.max(b,c);e.normal3(0,0,d?-1:1).texCoord2(.5,.5).vertex2(0,0);var k=H3DU.Math.PiTimes2/(2*a);d=Math.cos(k);for(var k=3.141592653589793>=k?Math.sqrt(1-d*d):-Math.sqrt(1-d*d),l=0,p=1,r=0;r<2*a;r++){var q=0===(r&1)?b:c,t=-l*q,q=p*q,u=.5*(1+t*h),w=.5*(1+q*h);0===r&&(f=t,g=q);e.texCoord2(u,w).vertex2(t,q);t=d*p-k*l;l=d*l+k*p;p=t}e.texCoord2(.5*(1+f*h),.5*(1+g*h)).vertex2(f,g);return e.toMeshBuffer()}};t.BufferAccessor=M;t.MeshBuffer=
u;t.Semantic=E;t.Lights=Y;t.LightSource=Aa;t.RenderPass=wa;t.CurveEval=ia;t.SurfaceEval=fa;t.ShaderProgram=z;t.BufferedMesh=H;t.FrameBuffer=ea;t.is3DContext=qa;t.renderLoop=function(a){a(window.performance.now());var b=function(c){window.requestAnimationFrame(b);a(c)};window.requestAnimationFrame(b)};t.createCanvasElement=function(a,b,c){var d=document.createElement("canvas");a&&a.appendChild(d);if("undefined"===typeof b||null===b)d.width=Math.ceil(d.clientWidth)+"";else{if(0>b)throw Error("width negative");
d.width=Math.ceil(b)+""}if("undefined"===typeof c||null===c)d.height=Math.ceil(d.clientHeight)+"";else{if(0>c)throw Error("height negative");d.height=Math.ceil(c)+""}return d};t.get3DOr2DContext=xa;t.get3DContext=function(a,b){var c=xa(a),d=null;c||"undefined"===typeof window.WebGLShader||null===window.WebGLShader?"undefined"===typeof window.WebGLShader||null===window.WebGLShader||qa(c)?c&&qa(c)||(d="This page requires a WebGL-supporting browser."):d="This page requires WebGL, but it failed to start. Your computer might not support WebGL.":
d="Failed to initialize graphics support required by this page.";return d?((b||window.alert)(d),null):c};t.getPromiseResults=ya;t.getPromiseResultsAll=function(a,b,c){return ya(a,b,c).then(function(a){return 0<a.failures.length?Promise.reject(a):Promise.resolve(a.successes)})};t.loadFileFromUrl=function(a,b){var c=b||"text";return new Promise(function(b,e){var d=new XMLHttpRequest;d.onreadystatechange=function(d){d=d.target;4===d.readyState&&(200<=d.status&&300>d.status?(d="xml"===c?d.responseXML:
"json"===c?"response"in d?d.response:JSON.parse(d.responseText):"arraybuffer"===c?d.response:d.responseText+"",b({url:a,data:d})):e({url:a}))};d.onerror=function(b){e({url:a,error:b})};d.open("get",a,!0);d.responseType=c;d.send()})};t.getTimePosition=function(a,b,c){if("undefined"===typeof a.time||null===a.time)return a.time=b,a.lastTime=b,0;if("undefined"===typeof a.lastTime||null===a.lastTime)a.lastTime=b;return 1*(b-a.time)%c/c};t.newFrames=function(a,b){if("undefined"===typeof a.time||null===
a.time)return a.time=b,a.lastTime=b,0;if("undefined"===typeof a.lastTime||null===a.lastTime)return a.lastTime=b,0;var c=b-a.lastTime;a.lastTime=b;return 60*c/1E3};t.toGLColor=function(a,b,c,d){return"undefined"===typeof a||null===a?[0,0,0,0]:"string"===typeof a?(a=za.colorToRgba(a)||[0,0,0,0],b=1/255,a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b,ua(a)):"number"===typeof a&&"number"===typeof b&&"number"===typeof c?[a,b,c,"number"!==typeof d?1:d]:a.constructor===Array?ua([a[0]||0,a[1]||0,a[2]||0,"number"!==typeof a[3]?
1:a[3]]):ua(a||[0,0,0,0])};Object.defineProperty(t,"__esModule",{value:!0})});var BezierCurve=H3DU.BezierCurve,BezierSurface=H3DU.BezierSurface,BSplineCurve=H3DU.BSplineCurve,BSplineSurface=H3DU.BSplineSurface,GLUtil=H3DU,GLMath=H3DU.Math,BufferedMesh=H3DU.BufferedMesh,FrameBuffer=H3DU.FrameBuffer,CurveEval=H3DU.CurveEval,SurfaceEval=H3DU.SurfaceEval,Lights=H3DU.Lights,LightSource=H3DU.LightSource,Material=H3DU.Material,Mesh=H3DU.Mesh,Meshes=H3DU.Meshes,Scene3D=H3DU.Scene3D,ShaderProgram=H3DU.ShaderProgram,Shape=H3DU.Shape,ShapeGroup=H3DU.ShapeGroup,Texture=H3DU.Texture,TextureLoader=
H3DU.TextureLoader,Transform=H3DU.Transform;
